function appendFormattedElement(&$wrapper, $data) { if (!is_array($data) || empty($data)) { return; } // If cache has expired refresh the data array from parsing the API XML if (time() - $data['last_updated'] > $this->_fields['refresh'] * 60) { $data = VimeoHelper::updateClipInfo($data['clip_id'], $this->_fields['id'], $wrapper->getAttribute('id'), $this->Database); } $video = new XMLElement($this->get('element_name')); $video->setAttributeArray(array('clip-id' => $data['clip_id'], 'width' => $data['width'], 'height' => $data['height'], 'duration' => $data['duration'], 'plays' => $data['plays'])); $video->appendChild(new XMLElement('title', General::sanitize($data['title']))); $video->appendChild(new XMLElement('caption', General::sanitize($data['caption']))); $user = new XMLElement('user'); $user->appendChild(new XMLElement('name', $data['user_name'])); $user->appendChild(new XMLElement('url', $data['user_url'])); $thumbnail = new XMLElement('thumbnail'); $thumbnail->setAttributeArray(array('width' => $data['thumbnail_width'], 'height' => $data['thumbnail_height'], 'size' => 'large')); $thumbnail->appendChild(new XMLElement('url', $data['thumbnail_url'])); $video->appendChild($thumbnail); $thumbnail = new XMLElement('thumbnail'); $thumbnail->setAttributeArray(array('width' => $data['thumbnail_medium_width'], 'height' => $data['thumbnail_medium_height'], 'size' => 'medium')); $thumbnail->appendChild(new XMLElement('url', $data['thumbnail_medium_url'])); $video->appendChild($thumbnail); $thumbnail = new XMLElement('thumbnail'); $thumbnail->setAttributeArray(array('width' => $data['thumbnail_small_width'], 'height' => $data['thumbnail_small_height'], 'size' => 'small')); $thumbnail->appendChild(new XMLElement('url', $data['thumbnail_small_url'])); $video->appendChild($thumbnail); $video->appendChild($user); $wrapper->appendChild($video); }
protected function __trigger() { ## Cookies only show up on page refresh. This flag helps in making sure the correct XML is being set $loggedin = false; if (isset($_REQUEST['action']['login'])) { $username = $_REQUEST['username']; $password = $_REQUEST['password']; $loggedin = $this->_Parent->login($username, $password); } else { $loggedin = $this->_Parent->isLoggedIn(); } if ($loggedin) { $result = new XMLElement('login-info'); $result->setAttribute('logged-in', 'true'); $author = $this->_Parent->Author; $result->setAttributeArray(array('id' => $author->get('id'), 'user-type' => $author->get('user_type'), 'primary-account' => $author->get('primary'))); $fields = array('name' => new XMLElement('name', $author->getFullName()), 'username' => new XMLElement('username', $author->get('username')), 'email' => new XMLElement('email', $author->get('email'))); if ($author->isTokenActive()) { $fields['author-token'] = new XMLElement('author-token', $author->createAuthToken()); } if ($section = $this->_Parent->Database->fetchRow(0, "SELECT `id`, `handle`, `name` FROM `tbl_sections` WHERE `id` = '" . $author->get('default_section') . "' LIMIT 1")) { $default_section = new XMLElement('default-section', $section['name']); $default_section->setAttributeArray(array('id' => $section['id'], 'handle' => $section['handle'])); $fields['default-section'] = $default_section; } foreach ($fields as $f) { $result->appendChild($f); } } else { $result = new XMLElement('user'); $result->setAttribute('logged-in', 'false'); } return $result; }
/** * This method will construct XML that represents the result of * an Event filter. * * @param string $name * The name of the filter * @param string $status * The status of the filter, either passed or failed. * @param XMLElement|string $message * Optionally, an XMLElement or string to be appended to this * `<filter>` element. XMLElement allows for more complex return * types. * @param array $attributes * An associative array of additional attributes to add to this * `<filter>` element * @return XMLElement */ public static function buildFilterElement($name, $status, $message = null, array $attributes = null) { $filter = new XMLElement('filter', !$message || is_object($message) ? null : $message, array('name' => $name, 'status' => $status)); if ($message instanceof XMLElement) { $filter->appendChild($message); } if (is_array($attributes)) { $filter->setAttributeArray($attributes); } return $filter; }
public function buildFilterElement($name, $status, $message = null, array $attr = null) { $ret = new XMLElement('filter', !$message || is_object($message) ? null : $message, array('name' => $name, 'status' => $status)); if (is_object($message)) { $ret->appendChild($message); } if (is_array($attr)) { $ret->setAttributeArray($attr); } return $ret; }
function grab(&$param_pool) { $tag_list_id = "38"; $result = new XMLElement("tag-cloud"); $tags = $this->_Parent->Database->fetch("SELECT DISTINCT(handle), COUNT(handle) AS count, value FROM sym_entries_data_{$tag_list_id} GROUP BY handle ORDER BY handle ASC"); foreach ($tags as $tag) { $tag_node = new XMLElement("tag", $tag["value"]); $tag_node->setAttributeArray(array("handle" => $tag["handle"], "count" => $tag["count"])); $result->appendChild($tag_node); } return $result; }
function view() { $this->setPageType('table'); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Translation Manager')))); $this->appendSubheading(__('Languages'), Widget::Anchor(__('Create New'), $this->_Parent->getCurrentPageURL() . 'edit/', __('Create new translation'), 'create button')); $link = new XMLElement('link'); $link->setAttributeArray(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => URL . '/extensions/translationmanager/assets/admin.css')); $this->addElementToHead($link, 500); $this->addScriptToHead(URL . '/extensions/translationmanager/assets/admin.js', 501); $default = $this->_tm->defaultDictionary(); $translations = $this->_tm->listAll(); $allextensions = $this->_Parent->ExtensionManager->listAll(); $current = $this->_Parent->Configuration->get('lang', 'symphony'); $warnings = array_shift($default); $allnames = array('symphony' => __('Symphony')); foreach ($allextensions as $extension => $about) { $allnames[$extension] = $about['name']; } $aTableHead = array(array(__('Name'), 'col'), array(__('Code'), 'col'), array(__('Extensions*'), 'col', array('title' => __('Out of %s (including Symphony)', array(count($allextensions) + 1)))), array(__('Translated*'), 'col', array('title' => __('Out of %1$s (with %2$s parser warnings)', array(count($default), count($warnings) > 0 ? count($warnings) : __('no'))))), array(__('Obsolete'), 'col'), array(__('Current'), 'col')); $aTableBody = array(); if (!is_array($translations) || empty($translations)) { $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', NULL, count($aTableHead))))); } else { foreach ($translations as $lang => $extensions) { $language = $this->_tm->get($lang); $translated = array_intersect_key(array_filter($language['dictionary'], 'trim'), $default); $obsolete = array_diff_key($language['dictionary'], $default); $names = array_intersect_key($allnames, array_fill_keys($extensions, true)); if (!$language['about']['name']) { $language['about']['name'] = $lang; } $td1 = Widget::TableData(Widget::Anchor($language['about']['name'], $this->_Parent->getCurrentPageURL() . 'edit/' . $lang . '/', $lang)); $td2 = Widget::TableData($lang); $td3 = Widget::TableData((string) count($extensions), NULL, NULL, NULL, array('title' => implode(', ', $names))); $td4 = Widget::TableData(count($translated) . ' <small>(' . floor(count($translated) / count($default) * 100) . '%)</small>'); $td5 = Widget::TableData((string) count($obsolete)); $td6 = Widget::TableData($lang == $current ? __('Yes') : __('No')); $td1->appendChild(Widget::Input('item', $lang, 'radio')); ## Add a row to the body array, assigning each cell to the row $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4, $td5, $td6), 'single' . ($lang == $this->_Parent->Configuration->get('lang', 'symphony') ? ' current' : '')); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'languages'); $this->Form->appendChild($table); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete')), array('switch', false, __('Make it current')), array('export', false, __('Export ZIP'))); $div->appendChild(Widget::Select('with-selected', $options)); $div->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit')); $this->Form->appendChild($div); }
function __viewEdit() { $link = new XMLElement('link'); $link->setAttributeArray(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => URL . '/extensions/configuration/assets/configuration.css')); $this->addElementToHead($link, 500); $this->setTitle('Symphony – Configuration Settings'); $this->setPageType('table'); $this->appendSubheading('Configuration Settings'); ## Table Headings $aTableHead = array(array('Group', 'col'), array('Setting', 'col'), array('Value', 'col')); ## Get Configuration Settings and display as a table list $config_settings = $this->_Parent->Configuration->get(); $tableData = array(); $count = 0; foreach ($config_settings as $key => $groups) { foreach ($groups as $name => $value) { $setting_group = $key; $setting_name = $name; $setting_value = $value; $setting_group_data = '<input name="settings[' . $count . '][group]" type="hidden" value="' . $setting_group . '" />' . $setting_group; $setting_name_data = '<input name="settings[' . $count . '][name]" type="hidden" value="' . $setting_name . '" />' . $setting_name; $tableData[] = Widget::TableData($setting_group_data); $tableData[] = Widget::TableData($setting_name_data); $tableData[] = Widget::TableData(Widget::Input('settings[' . $count . '][value]', $setting_value, 'text')); $count++; $aTableBody[] = Widget::TableRow($tableData, $bEven ? 'even' : NULL); $bEven = !$bEven; unset($tableData); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody)); $this->Form->appendChild($table); ## Save Button $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', 'Save Settings', 'submit', array('accesskey' => 's'))); $this->Form->appendChild($div); ## Notice Messages if (isset($this->_flag)) { switch ($this->_flag) { case 'saved': $this->pageAlert('Configuration Settings updated successfully.', AdministrationPage::PAGE_ALERT_NOTICE); break; case 'error': $this->pageAlert('An error occurred.', AdministrationPage::PAGE_ALERT_NOTICE); break; } } }
protected function __trigger() { // Cookies only show up on page refresh. // This flag helps in making sure the correct XML is being set $loggedin = false; if (isset($_REQUEST['action']['login'])) { $username = $_REQUEST['username']; $password = $_REQUEST['password']; $loggedin = Frontend::instance()->login($username, $password); } else { $loggedin = Frontend::instance()->isLoggedIn(); } if ($loggedin) { $result = new XMLElement('login-info'); $result->setAttribute('logged-in', 'true'); $author = null; if (is_callable(array('Symphony', 'Author'))) { $author = Symphony::Author(); } else { $author = Frontend::instance()->Author; } $result->setAttributeArray(array('id' => $author->get('id'), 'user-type' => $author->get('user_type'), 'primary-account' => $author->get('primary'))); $fields = array('name' => new XMLElement('name', $author->getFullName()), 'username' => new XMLElement('username', $author->get('username')), 'email' => new XMLElement('email', $author->get('email'))); if ($author->isTokenActive()) { $fields['author-token'] = new XMLElement('author-token', $author->createAuthToken()); } // Section if ($section = Symphony::Database()->fetchRow(0, "SELECT `id`, `handle`, `name` FROM `tbl_sections` WHERE `id` = '" . $author->get('default_area') . "' LIMIT 1")) { $default_area = new XMLElement('default-area', $section['name']); $default_area->setAttributeArray(array('id' => $section['id'], 'handle' => $section['handle'], 'type' => 'section')); $fields['default-area'] = $default_area; } else { $default_area = new XMLElement('default-area', $author->get('default_area')); $default_area->setAttribute('type', 'page'); $fields['default-area'] = $default_area; } foreach ($fields as $f) { $result->appendChild($f); } } else { $result = new XMLElement('user'); $result->setAttribute('logged-in', 'false'); } // param output Frontend::Page()->_param['login'] = $loggedin ? 'yes' : 'no'; Frontend::Page()->_param['login-filter'] = $loggedin ? 'yes,no' : 'yes'; return $result; }
public function grab(&$param_pool) { $s = $_SESSION[__SYM_COOKIE_PREFIX_ . 'cart']; $xml = new XMLElement('shopping-cart'); if (!is_array($s) || empty($s)) { $xml->appendChild(new XMLElement('empty')); return $xml; } $param_pool['ds-shopping-cart'] = implode(',', array_keys($s)); $total = null; foreach ($s as $key => $value) { $item = new XMLElement('item', null, array('id' => $key, 'num' => $value['num'], 'sum' => $value['sum'])); $xml->appendChild($item); $total = $total + $value['sum']; } $xml->setAttributeArray(array('items' => count($s), 'total' => $total)); return $xml; }
public function appendFormattedElement(&$wrapper, $data, $encode = false) { if (!is_array($data) || empty($data)) { return; } if (!is_array($data['file'])) { if (!$data['file']) { return; } $data = array('file' => array($data['file'])); } $item = new XMLElement($this->get('element_name')); $path = DOCROOT; $item->setAttributeArray(array('path' => str_replace(WORKSPACE, '', $path))); foreach ($data['file'] as $index => $file) { $item->appendChild(new XMLElement('item', General::sanitize($file), array('size' => General::formatFilesize(filesize($path . $file))))); } $wrapper->appendChild($item); }
public function execute(array &$param_pool = null) { $result = new XMLElement($this->dsParamROOTELEMENT); // When DS is called out of the Frontend context, this will enable // {$root} and {$workspace} parameters to be evaluated if (empty($this->_env)) { $this->_env['env']['pool'] = array('root' => URL, 'workspace' => WORKSPACE); } try { require_once TOOLKIT . '/class.gateway.php'; require_once TOOLKIT . '/class.xsltprocess.php'; require_once CORE . '/class.cacheable.php'; $this->dsParamURL = $this->parseParamURL($this->dsParamURL); if (isset($this->dsParamXPATH)) { $this->dsParamXPATH = $this->__processParametersInString(stripslashes($this->dsParamXPATH), $this->_env); } // Builds a Default Stylesheet to transform the resulting XML with $stylesheet = new XMLElement('xsl:stylesheet'); $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform')); $output = new XMLElement('xsl:output'); $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes')); $stylesheet->appendChild($output); $template = new XMLElement('xsl:template'); $template->setAttribute('match', '/'); $instruction = new XMLElement('xsl:copy-of'); // Namespaces if (isset($this->dsParamNAMESPACES) && is_array($this->dsParamNAMESPACES)) { foreach ($this->dsParamNAMESPACES as $name => $uri) { $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri); } } // XPath $instruction->setAttribute('select', $this->dsParamXPATH); $template->appendChild($instruction); $stylesheet->appendChild($template); $stylesheet->setIncludeHeader(true); $xsl = $stylesheet->generate(true); // Check for an existing Cache for this Datasource $cache_id = self::buildCacheID($this); $cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource'); $cachedData = $cache->check($cache_id); $writeToCache = null; $isCacheValid = true; $creation = DateTimeObj::get('c'); // Execute if the cache doesn't exist, or if it is old. if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) { if (Mutex::acquire($cache_id, $this->dsParamTIMEOUT, TMP)) { $ch = new Gateway(); $ch->init($this->dsParamURL); $ch->setopt('TIMEOUT', $this->dsParamTIMEOUT); // Set the approtiate Accept: headers depending on the format of the URL. if ($this->dsParamFORMAT == 'xml') { $ch->setopt('HTTPHEADER', array('Accept: text/xml, */*')); } elseif ($this->dsParamFORMAT == 'json') { $ch->setopt('HTTPHEADER', array('Accept: application/json, */*')); } elseif ($this->dsParamFORMAT == 'csv') { $ch->setopt('HTTPHEADER', array('Accept: text/csv, */*')); } self::prepareGateway($ch); $data = $ch->exec(); $info = $ch->getInfoLast(); Mutex::release($cache_id, TMP); $data = trim($data); $writeToCache = true; // Handle any response that is not a 200, or the content type does not include XML, JSON, plain or text if ((int) $info['http_code'] != 200 || !preg_match('/(xml|json|csv|plain|text)/i', $info['content_type'])) { $writeToCache = false; $result->setAttribute('valid', 'false'); // 28 is CURLE_OPERATION_TIMEOUTED if ($info['curl_error'] == 28) { $result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout))); } else { $result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type']))); } return $result; } else { if (strlen($data) > 0) { // Handle where there is `$data` // If it's JSON, convert it to XML if ($this->dsParamFORMAT == 'json') { try { require_once TOOLKIT . '/class.json.php'; $data = JSON::convertToXML($data); } catch (Exception $ex) { $writeToCache = false; $errors = array(array('message' => $ex->getMessage())); } } elseif ($this->dsParamFORMAT == 'csv') { try { require_once EXTENSIONS . '/remote_datasource/lib/class.csv.php'; $data = CSV::convertToXML($data); } catch (Exception $ex) { $writeToCache = false; $errors = array(array('message' => $ex->getMessage())); } } elseif ($this->dsParamFORMAT == 'txt') { $txtElement = new XMLElement('entry'); $txtElement->setValue(General::wrapInCDATA($data)); $data = $txtElement->generate(); $txtElement = null; } else { if (!General::validateXML($data, $errors, false, new XsltProcess())) { // If the XML doesn't validate.. $writeToCache = false; } } // If the `$data` is invalid, return a result explaining why if ($writeToCache === false) { $error = new XMLElement('errors'); $error->setAttribute('valid', 'false'); $error->appendChild(new XMLElement('error', __('Data returned is invalid.'))); foreach ($errors as $e) { if (strlen(trim($e['message'])) == 0) { continue; } $error->appendChild(new XMLElement('item', General::sanitize($e['message']))); } $result->appendChild($error); return $result; } } elseif (strlen($data) == 0) { // If `$data` is empty, set the `force_empty_result` to true. $this->_force_empty_result = true; } } } else { // Failed to acquire a lock $result->appendChild(new XMLElement('error', __('The %s class failed to acquire a lock.', array('<code>Mutex</code>')))); } } else { // The cache is good, use it! $data = trim($cachedData['data']); $creation = DateTimeObj::get('c', $cachedData['creation']); } // Visit the data $this->exposeData($data); // If `$writeToCache` is set to false, invalidate the old cache if it existed. if (is_array($cachedData) && !empty($cachedData) && $writeToCache === false) { $data = trim($cachedData['data']); $isCacheValid = false; $creation = DateTimeObj::get('c', $cachedData['creation']); if (empty($data)) { $this->_force_empty_result = true; } } // If `force_empty_result` is false and `$result` is an instance of // XMLElement, build the `$result`. if (!$this->_force_empty_result && is_object($result)) { $proc = new XsltProcess(); $ret = $proc->process($data, $xsl); if ($proc->isErrors()) { $result->setAttribute('valid', 'false'); $error = new XMLElement('error', __('Transformed XML is invalid.')); $result->appendChild($error); $errors = new XMLElement('errors'); foreach ($proc->getError() as $e) { if (strlen(trim($e['message'])) == 0) { continue; } $errors->appendChild(new XMLElement('item', General::sanitize($e['message']))); } $result->appendChild($errors); $result->appendChild(new XMLElement('raw-data', General::wrapInCDATA($data))); } elseif (strlen(trim($ret)) == 0) { $this->_force_empty_result = true; } else { if ($this->dsParamCACHE > 0 && $writeToCache) { $cache->write($cache_id, $data, $this->dsParamCACHE); } $result->setValue(PHP_EOL . str_repeat("\t", 2) . preg_replace('/([\\r\\n]+)/', "\$1\t", $ret)); $result->setAttribute('status', $isCacheValid === true ? 'fresh' : 'stale'); $result->setAttribute('cache-id', $cache_id); $result->setAttribute('creation', $creation); } } } catch (Exception $e) { $result->appendChild(new XMLElement('error', $e->getMessage())); } if ($this->_force_empty_result) { $result = $this->emptyXMLSet(); } $result->setAttribute('url', General::sanitize($this->dsParamURL)); return $result; }
<?php require_once TOOLKIT . '/class.gateway.php'; require_once TOOLKIT . '/class.xsltprocess.php'; require_once CORE . '/class.cacheable.php'; if (isset($this->dsParamURL)) { $this->dsParamURL = $this->__processParametersInString($this->dsParamURL, $this->_env, true, true); } if (isset($this->dsParamXPATH)) { $this->dsParamXPATH = $this->__processParametersInString($this->dsParamXPATH, $this->_env); } $stylesheet = new XMLElement('xsl:stylesheet'); $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform')); $output = new XMLElement('xsl:output'); $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes')); $stylesheet->appendChild($output); $template = new XMLElement('xsl:template'); $template->setAttribute('match', '/'); $instruction = new XMLElement('xsl:copy-of'); ## Namespaces foreach ($this->dsParamFILTERS as $name => $uri) { $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : NULL), $uri); } ## XPath $instruction->setAttribute('select', $this->dsParamXPATH); $template->appendChild($instruction); $stylesheet->appendChild($template); $stylesheet->setIncludeHeader(true); $xsl = $stylesheet->generate(true); $proc =& new XsltProcess(); $cache_id = md5($this->dsParamURL . serialize($this->dsParamFILTERS) . $this->dsParamXPATH);
function wrapFormElementWithError($element, $message) { $div = new XMLElement('div'); $div->setAttributeArray(array('id' => 'error', 'class' => 'invalid')); $div->appendChild($element); $div->appendChild(new XMLElement('p', $message)); return $div; }
public function __form($readonly = false) { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); // These alerts are only valid if the form doesn't have errors } elseif (isset($this->_context[2])) { $time = Widget::Time(); switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array("name" => null, "filters" => null); $about = array("name" => null); $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::EVENT); if (isset($_POST['fields'])) { $fields = $_POST['fields']; if ($this->_context[0] == 'edit') { $isEditing = true; } } elseif ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $existing = EventManager::create($handle); $about = $existing->about(); if ($this->_context[0] == 'edit' && !$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/events/info/' . $handle . '/'); } $fields['name'] = $about['name']; $fields['source'] = $existing->getSource(); $provided = false; if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { $fields = array_merge($fields, $existing->settings()); $provided = true; break; } } } if (!$provided) { if (isset($existing->eParamFILTERS)) { $fields['filters'] = $existing->eParamFILTERS; } } } // Handle name on edited changes, or from reading an edited datasource if (isset($about['name'])) { $name = $about['name']; } elseif (isset($fields['name'])) { $name = $fields['name']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($about['name'], __('Events'), __('Symphony')))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Events'), SYMPHONY_URL . '/blueprints/events/'))); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); // Target $sources = new XMLElement('div', null, array('class' => 'apply actions')); $div = new XMLElement('div'); $label = Widget::Label(__('Target'), null, 'apply-label-left'); $sources->appendChild($label); $sources->appendChild($div); $sections = SectionManager::fetch(null, 'ASC', 'name'); $options = array(); $section_options = array(); $source = isset($fields['source']) ? $fields['source'] : null; if (is_array($sections) && !empty($sections)) { $section_options = array('label' => __('Sections'), 'options' => array()); foreach ($sections as $s) { $section_options['options'][] = array($s->get('id'), $source == $s->get('id'), General::sanitize($s->get('name'))); } } $options[] = $section_options; // Loop over the event providers if (!empty($providers)) { $p = array('label' => __('From extensions'), 'options' => array()); foreach ($providers as $providerClass => $provider) { $p['options'][] = array($providerClass, $fields['source'] == $providerClass, $provider); } $options[] = $p; } $div->appendChild(Widget::Select('source', $options, array('id' => 'event-context'))); if (isset($this->_errors['source'])) { $this->Context->prependChild(Widget::Error($sources, $this->_errors['source'])); } else { $this->Context->prependChild($sources); } $this->Form->appendChild(Widget::Input('fields[source]', $options[0]['options'][0][0], 'hidden', array('id' => 'event-source'))); // Name $group = new XMLElement('div'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); $div = new XMLElement('div'); $div->setAttribute('class', 'column'); if (isset($this->_errors['name'])) { $div->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Filters $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings pickable'); $fieldset->appendChild(new XMLElement('legend', __('Filters'))); $p = new XMLElement('p', __('Event Filters add additional conditions or actions to an event.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $filters = isset($fields['filters']) ? $fields['filters'] : array(); $options = array(array('admin-only', in_array('admin-only', $filters), __('Admin Only')), array('send-email', in_array('send-email', $filters), __('Send Notification Email')), array('expect-multiple', in_array('expect-multiple', $filters), __('Allow Multiple'))); /** * Allows adding of new filter rules to the Event filter rule select box * * @delegate AppendEventFilter * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $options * An array of all the filters that are available, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'options' => &$options)); $fieldset->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple', 'id' => 'event-filters'))); $this->Form->appendChild($fieldset); // Connections $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Attach to Pages'))); $p = new XMLElement('p', __('The event will only be available on the selected pages.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $label = Widget::Label(__('Pages')); $pages = PageManager::fetch(); $event_handle = str_replace('-', '_', Lang::createHandle($fields['name'])); $connections = ResourceManager::getAttachedPages(RESOURCE_TYPE_EVENT, $event_handle); $selected = array(); foreach ($connections as $connection) { $selected[] = $connection['id']; } $options = array(); foreach ($pages as $page) { $options[] = array($page['id'], in_array($page['id'], $selected), PageManager::resolvePageTitle($page['id'])); } $label->appendChild(Widget::Select('fields[connections][]', $options, array('multiple' => 'multiple'))); $div->appendChild($label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Providers if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($isEditing && $fields['source'] !== call_user_func(array($providerClass, 'getSource'))) { continue; } call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle)); } } } else { // Author 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']); } else { $link = $about['author']['name']; } if ($link) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Author'))); $fieldset->appendChild(new XMLElement('p', $link->generate(false))); $this->Form->appendChild($fieldset); } // Version $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Version'))); $version = array_key_exists('version', $about) ? $about['version'] : null; $release_date = array_key_exists('release-date', $about) ? $about['release-date'] : filemtime(EventManager::__getDriverPath($handle)); if (preg_match('/^\\d+(\\.\\d+)*$/', $version)) { $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } elseif (!is_null($version)) { $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } else { $fieldset->appendChild(new XMLElement('p', __('Last modified on %s', array(DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } $this->Form->appendChild($fieldset); } // If we are editing an event, it assumed that the event has documentation $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('id', 'event-documentation'); $fieldset->setAttribute('class', 'settings'); if ($isEditing && method_exists($existing, 'documentation')) { $doc = $existing->documentation(); if ($doc) { $fieldset->setValue('<legend>' . __('Documentation') . '</legend>' . PHP_EOL . General::tabsToSpaces(is_object($doc) ? $doc->generate(true, 4) : $doc)); } } $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this event'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this event?'))); $div->appendChild($button); } if (!$readonly) { $this->Form->appendChild($div); } }
function view() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; ## Handle unknown context if (!in_array($this->_context[0], array('new', 'edit'))) { $this->_Parent->errorPageNotFound(); } ## Edit Utility context if ($this->_context[0] == 'edit') { $file_abs = UTILITIES . '/' . $this->_existing_file; $filename = $this->_existing_file; if (!@is_file($file_abs)) { redirect(URL . '/symphony/blueprints/utilities/new/'); } $fields['name'] = $filename; $fields['body'] = @file_get_contents($file_abs); $this->Form->setAttribute('action', URL . '/symphony/blueprints/utilities/edit/' . $this->_context[1] . '/'); } 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:template name=""> </xsl:template> </xsl:stylesheet>'; } $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Utility updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Utilities</a>', array(DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/utilities/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Utility created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Utilities</a>', array(DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/utilities/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; } } $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s' : '%1$s – %2$s – %3$s', array(__('Symphony'), __('Utilities'), $filename))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $filename); if (!empty($_POST)) { $fields = $_POST['fields']; } $fields['body'] = General::sanitize($fields['body']); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', $fields['name'])); $fieldset->appendChild(isset($this->_errors['name']) ? $this->wrapFormElementWithError($label, $this->_errors['name']) : $label); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[body]', 30, 80, $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'); $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]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Utility'), '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 utility'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __viewEdit() { $sectionManager = new SectionManager($this->_Parent); if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) { Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle']))); } $section = $sectionManager->fetch($section_id); $entry_id = intval($this->_context['entry_id']); $entryManager = new EntryManager($this->_Parent); $entryManager->setFetchSorting('id', 'DESC'); if (!($existingEntry = $entryManager->fetch($entry_id))) { Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.')); } $existingEntry = $existingEntry[0]; // If there is post data floating around, due to errors, create an entry object if (isset($_POST['fields'])) { $fields = $_POST['fields']; $entry =& $entryManager->create(); $entry->set('section_id', $existingEntry->get('section_id')); $entry->set('id', $entry_id); $entry->setDataFromPost($fields, $error, true); } else { $entry = $existingEntry; if (!$section) { $section = $sectionManager->fetch($entry->get('section_id')); } } /** * Just prior to rendering of an Entry edit form. * * @delegate EntryPreRender * @param string $context * '/publish/new/' * @param Section $section * @param Entry $entry * @param array $fields */ Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields)); if (isset($this->_context['flag'])) { $link = 'publish/' . $this->_context['section_handle'] . '/new/'; list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3); if (is_numeric($field_id) && $value) { $link .= "?prepopulate[{$field_id}]={$value}"; $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden')); } switch ($flag) { case 'saved': $this->pageAlert(__('Entry updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Entry created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS); break; } } ### Determine the page title $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1"); $field = $entryManager->fieldManager->fetch($field_id); $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id))); if (trim($title) == '') { $title = 'Untitled'; } // Check if there is a field to prepopulate if (isset($_REQUEST['prepopulate'])) { $field_id = array_shift(array_keys($_REQUEST['prepopulate'])); $value = stripslashes(rawurldecode(array_shift($_REQUEST['prepopulate']))); $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden')); } $this->setPageType('form'); $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), $section->get('name'), $title))); $this->appendSubheading($title); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden')); ### $primary = new XMLElement('fieldset'); $primary->setAttribute('class', 'primary'); $sidebar_fields = $section->fetchFields(NULL, 'sidebar'); $main_fields = $section->fetchFields(NULL, 'main'); if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) { $primary->appendChild(new XMLElement('p', __('It looks like you\'re trying to create an entry. Perhaps you want fields first? <a href="%s">Click here to create some.</a>', array(SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/')))); } else { if (is_array($main_fields) && !empty($main_fields)) { foreach ($main_fields as $field) { $primary->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($primary); } if (is_array($sidebar_fields) && !empty($sidebar_fields)) { $sidebar = new XMLElement('fieldset'); $sidebar->setAttribute('class', 'secondary'); foreach ($sidebar_fields as $field) { $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($sidebar); } } $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' => 'button confirm delete', 'title' => __('Delete this entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?'))); $div->appendChild($button); $this->Form->appendChild($div); }
public function execute(array &$param_pool = null) { $result = new XMLElement($this->dsParamROOTELEMENT); $this->dsParamURL = $this->parseParamURL($this->dsParamURL); if (isset($this->dsParamXPATH)) { $this->dsParamXPATH = $this->__processParametersInString($this->dsParamXPATH, $this->_env); } $stylesheet = new XMLElement('xsl:stylesheet'); $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform')); $output = new XMLElement('xsl:output'); $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes')); $stylesheet->appendChild($output); $template = new XMLElement('xsl:template'); $template->setAttribute('match', '/'); $instruction = new XMLElement('xsl:copy-of'); // Namespaces if (isset($this->dsParamFILTERS) && is_array($this->dsParamFILTERS)) { foreach ($this->dsParamFILTERS as $name => $uri) { $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri); } } // XPath $instruction->setAttribute('select', $this->dsParamXPATH); $template->appendChild($instruction); $stylesheet->appendChild($template); $stylesheet->setIncludeHeader(true); $xsl = $stylesheet->generate(true); $cache_id = md5($this->dsParamURL . serialize($this->dsParamFILTERS) . $this->dsParamXPATH); $cache = new Cacheable(Symphony::Database()); $cachedData = $cache->read($cache_id); $writeToCache = false; $valid = true; $creation = DateTimeObj::get('c'); $timeout = isset($this->dsParamTIMEOUT) ? (int) max(1, $this->dsParamTIMEOUT) : 6; // Execute if the cache doesn't exist, or if it is old. if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) { if (Mutex::acquire($cache_id, $timeout, TMP)) { $ch = new Gateway(); $ch->init($this->dsParamURL); $ch->setopt('TIMEOUT', $timeout); $ch->setopt('HTTPHEADER', array('Accept: text/xml, */*')); $data = $ch->exec(); $info = $ch->getInfoLast(); Mutex::release($cache_id, TMP); $data = trim($data); $writeToCache = true; // Handle any response that is not a 200, or the content type does not include XML, plain or text if ((int) $info['http_code'] !== 200 || !preg_match('/(xml|plain|text)/i', $info['content_type'])) { $writeToCache = false; $result->setAttribute('valid', 'false'); // 28 is CURLE_OPERATION_TIMEOUTED if ($info['curl_error'] == 28) { $result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout))); } else { $result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type']))); } return $result; // Handle where there is `$data` } elseif (strlen($data) > 0) { // If the XML doesn't validate.. if (!General::validateXML($data, $errors, false, new XsltProcess())) { $writeToCache = false; } // If the `$data` is invalid, return a result explaining why if ($writeToCache === false) { $element = new XMLElement('errors'); $result->setAttribute('valid', 'false'); $result->appendChild(new XMLElement('error', __('Data returned is invalid.'))); foreach ($errors as $e) { if (strlen(trim($e['message'])) == 0) { continue; } $element->appendChild(new XMLElement('item', General::sanitize($e['message']))); } $result->appendChild($element); return $result; } // If `$data` is empty, set the `force_empty_result` to true. } elseif (strlen($data) == 0) { $this->_force_empty_result = true; } // Failed to acquire a lock } else { $result->appendChild(new XMLElement('error', __('The %s class failed to acquire a lock, check that %s exists and is writable.', array('<code>Mutex</code>', '<code>' . TMP . '</code>')))); } // The cache is good, use it! } else { $data = trim($cachedData['data']); $creation = DateTimeObj::get('c', $cachedData['creation']); } // If `$writeToCache` is set to false, invalidate the old cache if it existed. if (is_array($cachedData) && !empty($cachedData) && $writeToCache === false) { $data = trim($cachedData['data']); $valid = false; $creation = DateTimeObj::get('c', $cachedData['creation']); if (empty($data)) { $this->_force_empty_result = true; } } // If `force_empty_result` is false and `$result` is an instance of // XMLElement, build the `$result`. if (!$this->_force_empty_result && is_object($result)) { $proc = new XsltProcess(); $ret = $proc->process($data, $xsl); if ($proc->isErrors()) { $result->setAttribute('valid', 'false'); $error = new XMLElement('error', __('Transformed XML is invalid.')); $result->appendChild($error); $element = new XMLElement('errors'); foreach ($proc->getError() as $e) { if (strlen(trim($e['message'])) == 0) { continue; } $element->appendChild(new XMLElement('item', General::sanitize($e['message']))); } $result->appendChild($element); } elseif (strlen(trim($ret)) == 0) { $this->_force_empty_result = true; } else { if ($writeToCache) { $cache->write($cache_id, $data, $this->dsParamCACHE); } $result->setValue(PHP_EOL . str_repeat("\t", 2) . preg_replace('/([\\r\\n]+)/', "\$1\t", $ret)); $result->setAttribute('status', $valid === true ? 'fresh' : 'stale'); $result->setAttribute('creation', $creation); } } return $result; }
public function __viewEdit() { $section_id = $this->_context[1]; $sectionManager = new SectionManager($this->_Parent); if (!($section = $sectionManager->fetch($section_id))) { $this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for could not be found.'), false, true); } $meta = $section->get(); $fieldManager = new FieldManager($this->_Parent); $types = array(); $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Section updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Sections</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/sections/new/', URL . '/symphony/blueprints/sections/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Section created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Sections</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/sections/new/', URL . '/symphony/blueprints/sections/')), Alert::SUCCESS); break; } } if (isset($_POST['fields'])) { $fields = array(); if (is_array($_POST['fields']) && !empty($_POST['fields'])) { foreach ($_POST['fields'] as $position => $data) { if ($fields[$position] = $fieldManager->create($data['type'])) { $fields[$position]->setArray($data); $fields[$position]->set('sortorder', $position); } } } } else { $fields = $fieldManager->fetch(NULL, $section_id); } $meta['subsection'] = $meta['subsection'] == 'yes' ? 1 : 0; $meta['entry_order'] = isset($meta['entry_order']) ? $meta['entry_order'] : 'date'; if (isset($_POST['meta'])) { $meta = $_POST['meta']; $meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no'; if ($meta['name'] == '') { $meta['name'] = $section->get('name'); } } $this->setPageType('form'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), __('Sections'), $meta['name']))); $this->appendSubheading($meta['name']); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div', NULL, array('class' => 'group')); $namediv = new XMLElement('div', NULL); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('meta[name]', $meta['name'])); if (isset($this->_errors['name'])) { $namediv->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $namediv->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('meta[hidden]', 'yes', 'checkbox', $meta['hidden'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Hide this section from the Publish menu', array($input->generate(false)))); $namediv->appendChild($label); $div->appendChild($namediv); $navgroupdiv = new XMLElement('div', NULL); $sectionManager = new SectionManager($this->_Parent); $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder'); $label = Widget::Label(__('Navigation Group') . ' <i>' . __('Choose only one. Created if does not exist') . '</i>'); $label->appendChild(Widget::Input('meta[navigation_group]', $meta['navigation_group'])); if (isset($this->_errors['navigation_group'])) { $navgroupdiv->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['navigation_group'])); } else { $navgroupdiv->appendChild($label); } if (is_array($sections) && !empty($sections)) { $ul = new XMLElement('ul', NULL, array('class' => 'tags singular')); $groups = array(); foreach ($sections as $s) { if (in_array($s->get('navigation_group'), $groups)) { continue; } $ul->appendChild(new XMLElement('li', $s->get('navigation_group'))); $groups[] = $s->get('navigation_group'); } $navgroupdiv->appendChild($ul); } $div->appendChild($navgroupdiv); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Fields'))); $div = new XMLElement('div'); $h3 = new XMLElement('h3', __('Fields')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $ol = new XMLElement('ol'); $ol->setAttribute('id', 'fields-duplicator'); if (is_array($fields) && !empty($fields)) { foreach ($fields as $position => $field) { $wrapper = new XMLElement('li'); $field->set('sortorder', $position); $field->displaySettingsPanel($wrapper, isset($this->_errors[$position]) ? $this->_errors[$position] : NULL); $ol->appendChild($wrapper); } } foreach ($fieldManager->fetchTypes() as $type) { if ($type = $fieldManager->create($type)) { array_push($types, $type); } } uasort($types, create_function('$a, $b', 'return strnatcasecmp($a->_name, $b->_name);')); foreach ($types as $type) { $defaults = array(); $type->findDefaults($defaults); $type->setArray($defaults); $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'template'); $type->set('sortorder', '-1'); $type->displaySettingsPanel($wrapper); $ol->appendChild($wrapper); } $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $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 section'), 'type' => 'submit')); $div->appendChild($button); $this->Form->appendChild($div); }
public function execute(array &$param_pool = null) { $author_ids = array(); if (is_array($this->dsParamFILTERS) && !empty($this->dsParamFILTERS)) { foreach ($this->dsParamFILTERS as $field => $value) { if (!is_array($value) && trim($value) == '') { continue; } $ret = $this->__processAuthorFilter($field, $value); if (empty($ret)) { $author_ids = array(); break; } if (empty($author_ids)) { $author_ids = $ret; continue; } $author_ids = array_intersect($author_ids, $ret); } $authors = AuthorManager::fetchByID(array_values($author_ids)); } else { $authors = AuthorManager::fetch($this->dsParamSORT, $this->dsParamORDER); } if ((!is_array($authors) || empty($authors)) && $this->dsParamREDIRECTONEMPTY == 'yes') { throw new FrontendPageNotFoundException(); } elseif (!is_array($authors) || empty($authors)) { $result = $this->emptyXMLSet(); return $result; } else { if (!$this->_param_output_only) { $result = new XMLElement($this->dsParamROOTELEMENT); } $singleParam = false; $key = 'ds-' . $this->dsParamROOTELEMENT; if (isset($this->dsParamPARAMOUTPUT)) { if (!is_array($this->dsParamPARAMOUTPUT)) { $this->dsParamPARAMOUTPUT = array($this->dsParamPARAMOUTPUT); } $singleParam = count($this->dsParamPARAMOUTPUT) === 1; } foreach ($authors as $author) { if (isset($this->dsParamPARAMOUTPUT)) { foreach ($this->dsParamPARAMOUTPUT as $param) { // The new style of paramater is `ds-datasource-handle.field-handle` $param_key = $key . '.' . str_replace(':', '-', $param); if (!is_array($param_pool[$param_key])) { $param_pool[$param_key] = array(); } $param_pool[$param_key][] = $param === 'name' ? $author->getFullName() : $author->get($param); if ($singleParam) { if (!is_array($param_pool[$key])) { $param_pool[$key] = array(); } $param_pool[$key][] = $param === 'name' ? $author->getFullName() : $author->get($param); } } } if ($this->_param_output_only) { continue; } $xAuthor = new XMLElement('author'); $xAuthor->setAttributeArray(array('id' => $author->get('id'), 'user-type' => $author->get('user_type'), 'primary-account' => $author->get('primary'))); // No included elements, so just create the Author XML if (!isset($this->dsParamINCLUDEDELEMENTS) || !is_array($this->dsParamINCLUDEDELEMENTS) || empty($this->dsParamINCLUDEDELEMENTS)) { $result->appendChild($xAuthor); } else { // Name if (in_array('name', $this->dsParamINCLUDEDELEMENTS)) { $xAuthor->appendChild(new XMLElement('name', $author->getFullName())); } // Username if (in_array('username', $this->dsParamINCLUDEDELEMENTS)) { $xAuthor->appendChild(new XMLElement('username', $author->get('username'))); } // Email if (in_array('email', $this->dsParamINCLUDEDELEMENTS)) { $xAuthor->appendChild(new XMLElement('email', $author->get('email'))); } // Author Token if (in_array('author-token', $this->dsParamINCLUDEDELEMENTS) && $author->isTokenActive()) { $xAuthor->appendChild(new XMLElement('author-token', $author->createAuthToken())); } // Default Area if (in_array('default-area', $this->dsParamINCLUDEDELEMENTS) && !is_null($author->get('default_area'))) { // Section if ($section = SectionManager::fetch($author->get('default_area'))) { $default_area = new XMLElement('default-area', $section->get('name')); $default_area->setAttributeArray(array('id' => $section->get('id'), 'handle' => $section->get('handle'), 'type' => 'section')); $xAuthor->appendChild($default_area); } else { $default_area = new XMLElement('default-area', $author->get('default_area')); $default_area->setAttribute('type', 'page'); $xAuthor->appendChild($default_area); } } $result->appendChild($xAuthor); } } } return $result; }
public function __form() { require_once TOOLKIT . '/class.field.php'; // Handle unknown context if (!in_array($this->_context[0], array('new', 'edit'))) { Administration::instance()->errorPageNotFound(); } if ($this->_context[0] == 'new' && !Administration::instance()->Author->isDeveloper()) { Administration::instance()->customError(__('Access Denied'), __('You are not authorised to access this page.')); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Author updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' . __('View all Authors') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Author created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' . __('View all Authors') . '</a>', Alert::SUCCESS); break; } } $this->setPageType('form'); $isOwner = false; if (isset($_POST['fields'])) { $author = $this->_Author; } else { if ($this->_context[0] == 'edit') { if (!($author_id = $this->_context[1])) { redirect(SYMPHONY_URL . '/system/authors/'); } if (!($author = AuthorManager::fetchByID($author_id))) { Administration::instance()->customError(__('Author not found'), __('The author profile you requested does not exist.')); } } else { $author = new Author(); } } if ($this->_context[0] == 'edit' && $author->get('id') == Administration::instance()->Author->get('id')) { $isOwner = true; } if ($this->_context[0] == 'edit' && !$isOwner && !Administration::instance()->Author->isDeveloper()) { Administration::instance()->customError(__('Access Denied'), __('You are not authorised to edit other authors.')); } $this->setTitle(__($this->_context[0] == 'new' ? '%2$s – %3$s' : '%1$s – %2$s – %3$s', array($author->getFullName(), __('Authors'), __('Symphony')))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $author->getFullName()); $this->insertBreadcrumbs(array(Widget::Anchor(__('Authors'), SYMPHONY_URL . '/system/authors/'))); // Essentials $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'two columns'); $label = Widget::Label(__('First Name'), NULL, 'column'); $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name'))); $div->appendChild(isset($this->_errors['first_name']) ? Widget::Error($label, $this->_errors['first_name']) : $label); $label = Widget::Label(__('Last Name'), NULL, 'column'); $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name'))); $div->appendChild(isset($this->_errors['last_name']) ? Widget::Error($label, $this->_errors['last_name']) : $label); $group->appendChild($div); $label = Widget::Label(__('Email Address')); $label->appendChild(Widget::Input('fields[email]', $author->get('email'))); $group->appendChild(isset($this->_errors['email']) ? Widget::Error($label, $this->_errors['email']) : $label); $this->Form->appendChild($group); // Login Details $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Login Details'))); $div = new XMLElement('div'); $label = Widget::Label(__('Username')); $label->appendChild(Widget::Input('fields[username]', $author->get('username'))); $div->appendChild(isset($this->_errors['username']) ? Widget::Error($label, $this->_errors['username']) : $label); // Only developers can change the user type. Primary account should NOT be able to change this if (Administration::instance()->Author->isDeveloper() && !$author->isPrimaryAccount()) { // Create columns $div->setAttribute('class', 'two columns'); $label->setAttribute('class', 'column'); // User type $label = Widget::Label(__('User Type'), NULL, 'column'); $options = array(array('author', false, __('Author')), array('developer', $author->isDeveloper(), __('Developer'))); $label->appendChild(Widget::Select('fields[user_type]', $options)); $div->appendChild($label); } $group->appendChild($div); // Password $fieldset = new XMLElement('fieldset', NULL, array('class' => 'two columns', 'id' => 'password')); $legend = new XMLElement('legend', __('Password')); $help = new XMLElement('i', __('Leave password fields blank to keep the current password')); $fieldset->appendChild($legend); $fieldset->appendChild($help); // Password reset if ($this->_context[0] == 'edit' && (!Administration::instance()->Author->isDeveloper() || $isOwner === true)) { $fieldset->setAttribute('class', 'three columns'); $label = Widget::Label(NULL, NULL, 'column'); $label->appendChild(Widget::Input('fields[old-password]', NULL, 'password', array('placeholder' => __('Old Password')))); $fieldset->appendChild(isset($this->_errors['old-password']) ? Widget::Error($label, $this->_errors['password']) : $label); } // New password $callback = Administration::instance()->getPageCallback(); $placeholder = $callback['context'][0] == 'edit' ? __('New Password') : __('Password'); $label = Widget::Label(NULL, NULL, 'column'); $label->appendChild(Widget::Input('fields[password]', NULL, 'password', array('placeholder' => $placeholder))); $fieldset->appendChild(isset($this->_errors['password']) ? Widget::Error($label, $this->_errors['password']) : $label); // Confirm password $label = Widget::Label(NULL, NULL, 'column'); $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password', array('placeholder' => __('Confirm Password')))); $fieldset->appendChild(isset($this->_errors['password-confirmation']) ? Widget::Error($label, $this->_errors['password']) : $label); $group->appendChild($fieldset); // Auth token if (Administration::instance()->Author->isDeveloper()) { $label = Widget::Label(); $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox'); if ($author->isTokenActive()) { $input->setAttribute('checked', 'checked'); } $temp = SYMPHONY_URL . '/login/' . $author->createAuthToken() . '/'; $label->setValue(__('%s Allow remote login via', array($input->generate())) . ' <a href="' . $temp . '">' . $temp . '</a>'); $group->appendChild($label); } $label = Widget::Label(__('Default Area')); $sections = SectionManager::fetch(NULL, 'ASC', 'sortorder'); $options = array(); // If the Author is the Developer, allow them to set the Default Area to // be the Sections Index. if ($author->isDeveloper()) { $options[] = array('/blueprints/sections/', $author->get('default_area') == '/blueprints/sections/', __('Sections Index')); } if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $author->get('default_area') == $s->get('id'), $s->get('name')); } } /** * Allows injection or manipulation of the Default Area dropdown for an Author. * Take care with adding in options that are only valid for Developers, as if a * normal Author is set to that option, they will be redirected to their own * Author record. * * * @delegate AddDefaultAuthorAreas * @since Symphony 2.2 * @param string $context * '/system/authors/' * @param array $options * An associative array of options, suitable for use for the Widget::Select * function. By default this will be an array of the Sections in the current * installation. New options should be the path to the page after the `SYMPHONY_URL` * constant. * @param string $default_area * The current `default_area` for this Author. */ Symphony::ExtensionManager()->notifyMembers('AddDefaultAuthorAreas', '/system/authors/', array('options' => &$options, 'default_area' => $author->get('default_area'))); $label->appendChild(Widget::Select('fields[default_area]', $options)); $group->appendChild($label); $this->Form->appendChild($group); // Custom Language Selection $languages = Lang::getAvailableLanguages(); if (count($languages) > 1) { // Get language names asort($languages); $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Custom Preferences'))); $label = Widget::Label(__('Language')); $options = array(array(NULL, is_null($author->get('language')), __('System Default'))); foreach ($languages as $code => $name) { $options[] = array($code, $code == $author->get('language'), $name); } $select = Widget::Select('fields[language]', $options); $label->appendChild($select); $group->appendChild($label); $this->Form->appendChild($group); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Author'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit' && !$isOwner && !$author->isPrimaryAccount()) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this author'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this author?'))); $div->appendChild($button); } $this->Form->appendChild($div); /** * Allows the injection of custom form fields given the current `$this->Form` * object. Please note that this custom data should be saved in own extension * tables and that modifying `tbl_authors` to house your data is highly discouraged. * * @delegate AddElementstoAuthorForm * @since Symphony 2.2 * @param string $context * '/system/authors/' * @param XMLElement $form * The contents of `$this->Form` after all the default form elements have been appended. * @param Author $author * The current Author object that is being edited */ Symphony::ExtensionManager()->notifyMembers('AddElementstoAuthorForm', '/system/authors/', array('form' => &$this->Form, 'author' => $author)); }
/** * Convenience function to add a stylesheet to the `$this->_head` in a `<link>` element. * By default the function will allow duplicates to be added to the `$this->_head`. * A duplicate is determined by if the `$path` is unique. * * @param string $path * The path to the stylesheet file * @param string $type * The media attribute for this stylesheet, defaults to 'screen' * @param integer $position * The desired position that the resulting XMLElement will be placed * in the `$this->_head`. Defaults to null which will append to the end. * @param boolean $duplicate * When set to false the function will only add the script if it doesn't * already exist. Defaults to true which allows duplicates. * @return integer * Returns the position that the stylesheet has been set in the `$this->_head` */ public function addStylesheetToHead($path, $type = 'screen', $position = null, $duplicate = true) { if ($duplicate === true || $duplicate === false && $this->checkElementsInHead($path, 'href') === false) { $link = new XMLElement('link'); $link->setAttributeArray(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => $type, 'href' => $path)); return $this->addElementToHead($link, $position); } }
/** * Will wrap a `<div>` around a desired element to trigger the default * Symphony error styling. * * @since Symphony 2.3 * @param XMLElement $element * The element that should be wrapped with an error * @param string $message * The text for this error. This will be appended after the $element, * but inside the wrapping `<div>` * @return XMLElement */ public static function Error(XMLElement $element, $message) { General::ensureType(array('message' => array('var' => $message, 'type' => 'string'))); $div = new XMLElement('div'); $div->setAttributeArray(array('class' => 'invalid')); $div->appendChild($element); $div->appendChild(new XMLElement('p', $message)); return $div; }
function __form($readonly = false) { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/events/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/events/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array(); $sectionManager = new SectionManager($this->_Parent); if ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $EventManager = new EventManager($this->_Parent); $existing =& $EventManager->create($handle); $about = $existing->about(); $fields['name'] = $about['name']; $fields['source'] = $existing->getSource(); $fields['filters'] = $existing->eParamFILTERS; } if (isset($_POST['fields'])) { $fields = $_POST['fields']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Events'), $about['name']))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $div->appendChild($label); } $label = Widget::Label(__('Source')); $sections = $sectionManager->fetch(NULL, 'ASC', 'name'); $options = array(); if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $fields['source'] == $s->get('id'), $s->get('name')); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context'))); $div->appendChild($label); $fieldset->appendChild($div); $label = Widget::Label(__('Filter Rules')); $options = array(array('admin-only', @in_array('admin-only', $fields['filters']), __('Admin Only')), array('send-email', @in_array('send-email', $fields['filters']), __('Send Email')), array('expect-multiple', @in_array('expect-multiple', $fields['filters']), __('Allow Multiple'))); ### # Delegate: AppendEventFilter # Description: Allows adding of new filter rules to the Event filter rule select box. A reference to the $options array is provided, and selected filters $this->_Parent->ExtensionManager->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $fields['filters'], 'options' => &$options)); $label->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $fieldset->appendChild(new XMLElement('p', __('This event will not be processed if any of these rules return true.'), array('class' => 'help'))); $this->Form->appendChild($fieldset); } if ($isEditing) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $doc = $existing->documentation(); $fieldset->setValue('<legend>' . __('Description') . '</legend>' . self::CRLF . General::tabsToSpaces(is_object($doc) ? $doc->generate(true) : $doc, 2)); $this->Form->appendChild($fieldset); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this event'), 'type' => 'submit')); $div->appendChild($button); } if (!$readonly) { $this->Form->appendChild($div); } }
public function appendFormattedElement(&$wrapper, $data) { // It is possible an array of NULL data will be passed in. Check for this. if (!is_array($data) || !isset($data['file']) || is_null($data['file'])) { return; } $item = new XMLElement($this->get('element_name')); $file = WORKSPACE . $data['file']; $item->setAttributeArray(array('size' => file_exists($file) && is_readable($file) ? General::formatFilesize(filesize($file)) : 'unknown', 'path' => str_replace(WORKSPACE, NULL, dirname(WORKSPACE . $data['file'])), 'type' => $data['mimetype'])); $item->appendChild(new XMLElement('filename', General::sanitize(basename($data['file'])))); $m = unserialize($data['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', NULL, $m)); } $wrapper->appendChild($item); }
function __form() { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Data source updated at %1$s. <a href="%2$s">Create another?</a> <a href="%2$s">View all Data sources</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/datasources/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Data source created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Data source</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/datasources/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; } } $sectionManager = new SectionManager($this->_Parent); if (isset($_POST['fields'])) { $fields = $_POST['fields']; if (!in_array($fields['source'], array('authors', 'navigation', 'dynamic_xml', 'static_xml')) && is_array($fields['filter']) && !empty($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } $fields['filter'][$fields['source']] = $filters; } } elseif ($this->_context[0] == 'edit') { $isEditing = true; $handle = $this->_context[1]; $datasourceManager = new DatasourceManager($this->_Parent); $existing =& $datasourceManager->create($handle, NULL, false); if (!$existing->allowEditorToParse()) { redirect(URL . '/symphony/blueprints/datasources/info/' . $handle . '/'); } $about = $existing->about(); $fields['name'] = $about['name']; $fields['order'] = $existing->dsParamORDER; $fields['param'] = $existing->dsParamPARAMOUTPUT; $fields['required_url_param'] = $existing->dsParamREQUIREDPARAM; $fields['xml_elements'] = $existing->dsParamINCLUDEDELEMENTS; $fields['sort'] = $existing->dsParamSORT; $fields['page_number'] = $existing->dsParamSTARTPAGE; $fields['limit_type'] = $existing->dsParamLIMITTYPE; $fields['group'] = $existing->dsParamGROUP; $fields['html_encode'] = $existing->dsParamHTMLENCODE; if ($existing->dsParamREDIRECTONEMPTY == 'yes') { $fields['redirect_on_empty'] = 'yes'; } $existing->dsParamFILTERS = @array_map('stripslashes', $existing->dsParamFILTERS); $fields['source'] = $existing->getSource(); switch ($fields['source']) { case 'authors': $fields['filter']['author'] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; case 'navigation': $fields['filter']['navigation'] = $existing->dsParamFILTERS; break; case 'dynamic_xml': $namespaces = $existing->dsParamFILTERS; $fields['dynamic_xml'] = array('namespace' => array()); $fields['dynamic_xml']['namespace']['name'] = @array_keys($namespaces); $fields['dynamic_xml']['namespace']['uri'] = @array_values($namespaces); $fields['dynamic_xml']['url'] = $existing->dsParamURL; $fields['dynamic_xml']['xpath'] = $existing->dsParamXPATH; $fields['dynamic_xml']['cache'] = $existing->dsParamCACHE; break; case 'static_xml': $fields['static_xml'] = trim($existing->grab()); break; default: $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; } } else { $fields['dynamic_xml']['url'] = 'http://'; $fields['dynamic_xml']['cache'] = '30'; $fields['dynamic_xml']['xpath'] = '/'; $fields['max_records'] = '20'; $fields['page_number'] = '1'; $fields['order'] = 'desc'; $fields['limit_type'] = 'entries'; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Data Sources'), $about['name']))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $div->appendChild($label); } $label = Widget::Label(__('Source')); $sections = $sectionManager->fetch(NULL, 'ASC', 'name'); foreach ($sections as $section) { $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); } $options = array(array('label' => __('System'), 'options' => array(array(__('authors'), $fields['source'] == __('authors'), __('Authors')), array(__('navigation'), $fields['source'] == __('navigation'), __('Navigation')))), array('label' => __('Custom XML'), 'options' => array(array(__('dynamic_xml'), $fields['source'] == __('dynamic_xml'), __('Dynamic XML')), array(__('static_xml'), $fields['source'] == __('static_xml'), __('Static XML'))))); if (is_array($sections) && !empty($sections)) { array_unshift($options, array('label' => __('Sections'), 'options' => array())); foreach ($sections as $s) { $options[0]['options'][] = array($s->get('id'), $fields['source'] == $s->get('id'), $s->get('name')); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context'))); $div->appendChild($label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __('sections') . ' ' . __('authors') . ' ' . __('navigation') . ' ' . __('Sections') . ' ' . __('System')); $fieldset->appendChild(new XMLElement('legend', __('Filter Results'))); $p = new XMLElement('p', __('Use <code>{$param}</code> syntax to filter by page parameters.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); foreach ($field_groups as $section_id => $section_data) { $div = new XMLElement('div'); $div->setAttribute('class', 'subsection contextual ' . $section_data['section']->get('id')); $div->appendChild(new XMLElement('h3', __('Filter %s by', array($section_data['section']->get('name'))))); $ol = new XMLElement('ol'); if (isset($fields['filter'][$section_data['section']->get('id')]['id'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->appendChild(new XMLElement('h4', __('System ID'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]', General::sanitize($fields['filter'][$section_data['section']->get('id')]['id']))); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('h4', __('System ID'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]')); $li->appendChild($label); $ol->appendChild($li); foreach ($section_data['fields'] as $input) { if (!$input->canFilter()) { continue; } if (isset($fields['filter'][$section_data['section']->get('id')][$input->get('id')])) { $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique'); $input->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_data['section']->get('id')][$input->get('id')], $this->_errors[$input->get('id')], $section_data['section']->get('id')); $ol->appendChild($wrapper); } $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique template'); $input->displayDatasourceFilterPanel($wrapper, NULL, NULL, $section_data['section']->get('id')); $ol->appendChild($wrapper); } $div->appendChild($ol); $fieldset->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'subsection contextual ' . __('authors')); $div->appendChild(new XMLElement('h3', __('Filter Authors by'))); $ol = new XMLElement('ol'); $this->__appendAuthorFilter($ol, __('ID'), 'id', $fields['filter']['author']['id'], !isset($fields['filter']['author']['id'])); $this->__appendAuthorFilter($ol, __('Username'), 'username', $fields['filter']['author']['username'], !isset($fields['filter']['author']['username'])); $this->__appendAuthorFilter($ol, __('First Name'), 'first_name', $fields['filter']['author']['first_name'], !isset($fields['filter']['author']['first_name'])); $this->__appendAuthorFilter($ol, __('Last Name'), 'last_name', $fields['filter']['author']['last_name'], !isset($fields['filter']['author']['last_name'])); $this->__appendAuthorFilter($ol, __('Email'), 'email', $fields['filter']['author']['email'], !isset($fields['filter']['author']['email'])); $this->__appendAuthorFilter($ol, __('User Type'), 'user_type', $fields['filter']['author']['user_type'], !isset($fields['filter']['author']['user_type'])); $div->appendChild($ol); $fieldset->appendChild($div); $div = new XMLElement('div'); $div->setAttribute('class', 'subsection contextual ' . __('navigation')); $div->appendChild(new XMLElement('h3', __('Filter Navigation by'))); $ol = new XMLElement('ol'); $pages = $this->_Parent->Database->fetch("SELECT * FROM `tbl_pages` ORDER BY `title` ASC"); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); foreach ($pages as $page) { $ul->appendChild(new XMLElement('li', preg_replace('/\\/{2,}/i', '/', '/' . $page['path'] . '/' . $page['handle']))); } if (isset($fields['filter']['navigation']['parent'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->appendChild(new XMLElement('h4', __('Parent Page'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]', General::sanitize($fields['filter']['navigation']['parent']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('h4', __('Parent Page'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); if ($types = $this->__fetchAvailablePageTypes()) { foreach ($types as $type) { $ul->appendChild(new XMLElement('li', $type)); } } if (isset($fields['filter']['navigation']['type'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->appendChild(new XMLElement('h4', __('Page Type'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]', General::sanitize($fields['filter']['navigation']['type']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('h4', __('Page Type'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse ' . __('static_xml') . ' ' . __('dynamic_xml')); $fieldset->appendChild(new XMLElement('legend', __('Sorting and Limiting'))); $p = new XMLElement('p', __('Use <code>{$param}</code> syntax to limit by page parameters.')); $p->setAttribute('class', 'help contextual inverse ' . __('navigation')); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'group contextual ' . __('sections') . ' ' . __('Sections')); $label = Widget::Label(__('Sort By')); $options = array(array('label' => __('Authors'), 'options' => array(array('id', $fields['source'] == 'authors' && $fields['sort'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['sort'] == 'username', __('Username')), array('first-name', $fields['source'] == 'authors' && $fields['sort'] == 'first-name', __('First Name')), array('last-name', $fields['source'] == 'authors' && $fields['sort'] == 'last-name', __('Last Name')), array('email', $fields['source'] == 'authors' && $fields['sort'] == 'email', __('Email')), array('status', $fields['source'] == 'authors' && $fields['sort'] == 'status', __('Status')))), array('label' => __('Navigation'), 'options' => array(array('id', $fields['source'] == 'navigation' && $fields['sort'] == 'id', __('Page ID')), array('handle', $fields['source'] == 'navigation' && $fields['sort'] == 'handle', __('Handle')), array('sortorder', $fields['source'] == 'navigation' && $fields['sort'] == 'sortorder', __('Sort Order'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array(array('system:id', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:id', __('System ID')), array('system:date', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:date', __('System Date')))); foreach ($section_data['fields'] as $input) { if (!$input->isSortable()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && $input->get('element_name') == $fields['sort'], $input->get('label')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[sort]', $options, array('class' => 'filtered'))); $div->appendChild($label); $label = Widget::Label(__('Sort Order')); $options = array(array('asc', 'asc' == $fields['order'], __('ascending')), array('desc', 'desc' == $fields['order'], __('descending')), array('rand', 'rand' == $fields['order'], __('random'))); $label->appendChild(Widget::Select('fields[order]', $options)); $div->appendChild($label); $fieldset->appendChild($div); $div = new XMLElement('div'); $div->setAttribute('class', 'group contextual inverse ' . __('navigation')); $label = Widget::Label(); $input = Widget::Input('fields[max_records]', $fields['max_records'], NULL, array('size' => '6')); $label->setValue(__('Show a maximum of %s results', array($input->generate(false)))); if (isset($this->_errors['max_records'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['max_records'])); } else { $div->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('fields[page_number]', $fields['page_number'], NULL, array('size' => '6')); $label->setValue(__('Show page %s of results', array($input->generate(false)))); if (isset($this->_errors['page_number'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['page_number'])); } else { $div->appendChild($label); } $fieldset->appendChild($div); $label = Widget::Label(__('Required URL Parameter <i>Optional</i>')); $label->appendChild(Widget::Input('fields[required_url_param]', $fields['required_url_param'])); $fieldset->appendChild($label); $p = new XMLElement('p', __('An empty result will be returned when this parameter does not have a value.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[redirect_on_empty]', 'yes', 'checkbox', isset($fields['redirect_on_empty']) ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Redirect to 404 page when no results are found', array($input->generate(false)))); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse ' . __('navigation') . ' ' . __('static_xml') . ' ' . __('dynamic_xml')); $fieldset->appendChild(new XMLElement('legend', __('Output Options'))); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'group'); $li = new XMLElement('li'); $li->appendChild(new XMLElement('h3', __('Parameter Output'))); $label = Widget::Label(__('Use Field')); $options = array(array('', false, __('None')), array('label' => __('Authors'), 'options' => array(array('id', $fields['source'] == 'authors' && $fields['param'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['param'] == 'username', __('Username')), array('name', $fields['source'] == 'authors' && $fields['param'] == 'name', __('Name')), array('email', $fields['source'] == 'authors' && $fields['param'] == 'email', __('Email')), array('user_type', $fields['source'] == 'authors' && $fields['param'] == 'user_type', __('User type'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array(array('system:id', $fields['source'] == $section_data['section']->get('id') && $fields['param'] == 'system:id', __('System ID')), array('system:date', $fields['source'] == $section_data['section']->get('id') && $fields['param'] == 'system:date', __('System Date')), array('system:author', $fields['source'] == $section_data['section']->get('id') && $fields['param'] == 'system:author', __('System Author')))); $authorOverride = false; foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceParamOutput()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && $fields['param'] == $input->get('element_name'), $input->get('label')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[param]', $options, array('class' => 'filtered'))); $li->appendChild($label); $p = new XMLElement('p', __('The parameter <code id="output-param-name">$ds-%s</code> will be created with this field\'s value for XSLT or other data sources to use.', array($this->_context[0] == 'edit' ? $existing->dsParamROOTELEMENT : __('Untitled')))); $p->setAttribute('class', 'help'); $li->appendChild($p); $ul->appendChild($li); $li = new XMLElement('li'); $li->appendChild(new XMLElement('h3', __('XML Output'))); $label = Widget::Label(__('Group By')); $options = array(array('', NULL, __('None'))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); $authorOverride = false; foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceOutputGrouping()) { continue; } if ($input->get('element_name') == 'author') { $authorOverride = true; } $optgroup['options'][] = array($input->get('id'), $fields['source'] == $section_data['section']->get('id') && $fields['group'] == $input->get('id'), $input->get('label')); } if (!$authorOverride) { $optgroup['options'][] = array('author', $fields['source'] == $section_data['section']->get('id') && $fields['group'] == 'author', __('Author')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[group]', $options, array('class' => 'filtered'))); $li->appendChild($label); $label = Widget::Label(__('Included Elements')); $options = array(array('label' => __('Authors'), 'options' => array(array('username', $fields['source'] == 'authors' && in_array('username', $fields['xml_elements']), 'username'), array('name', $fields['source'] == 'authors' && in_array('name', $fields['xml_elements']), 'name'), array('email', $fields['source'] == 'authors' && in_array('email', $fields['xml_elements']), 'email'), array('author-token', $fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements']), 'author-token'), array('default-section', $fields['source'] == 'authors' && in_array('default-section', $fields['xml_elements']), 'default-section'), array('formatting-preference', $fields['source'] == 'authors' && in_array('formatting-preference', $fields['xml_elements']), 'formatting-preference')))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); $optgroup['options'][] = array('system:pagination', $fields['source'] == $section_data['section']->get('id') && @in_array('system:pagination', $fields['xml_elements']), 'pagination'); foreach ($section_data['fields'] as $input) { $elements = $input->fetchIncludableElements(); foreach ($elements as $e) { $optgroup['options'][] = array($e, $fields['source'] == $section_data['section']->get('id') && @in_array($e, $fields['xml_elements']), $e); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple', 'class' => 'filtered'))); $li->appendChild($label); $label = Widget::Label(); $label->setAttribute('class', 'contextual inverse ' . __('authors')); $input = Widget::Input('fields[html_encode]', 'yes', 'checkbox', isset($fields['html_encode']) ? array('checked' => 'checked') : NULL); $label->setValue(__('%s HTML-encode text', array($input->generate(false)))); $li->appendChild($label); $ul->appendChild($li); $fieldset->appendChild($ul); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __('dynamic_xml')); $fieldset->appendChild(new XMLElement('legend', __('Dynamic XML'))); $label = Widget::Label(__('URL')); $label->appendChild(Widget::Input('fields[dynamic_xml][url]', General::sanitize($fields['dynamic_xml']['url']))); if (isset($this->_errors['dynamic_xml']['url'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['dynamic_xml']['url'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use <code>{$param}</code> syntax to specify dynamic portions of the URL.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'subsection'); $div->appendChild(new XMLElement('h3', __('Namespace Declarations <i>Optional</i>'))); $ol = new XMLElement('ol'); if (is_array($fields['dynamic_xml']['namespace']['name'])) { $namespaces = $fields['dynamic_xml']['namespace']['name']; $uri = $fields['dynamic_xml']['namespace']['uri']; for ($ii = 0; $ii < count($namespaces); $ii++) { $li = new XMLElement('li'); $li->appendChild(new XMLElement('h4', 'Namespace')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][name][]', General::sanitize($namespaces[$ii]))); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][uri][]', General::sanitize($uri[$ii]))); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); } } $li = new XMLElement('li'); $li->setAttribute('class', 'template'); $li->appendChild(new XMLElement('h4', __('Namespace'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][name][]')); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][uri][]')); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $label = Widget::Label(__('Included Elements')); $label->appendChild(Widget::Input('fields[dynamic_xml][xpath]', General::sanitize($fields['dynamic_xml']['xpath']))); if (isset($this->_errors['dynamic_xml']['xpath'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['dynamic_xml']['xpath'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use an XPath expression to select which elements from the source XML to include.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[dynamic_xml][cache]', max(1, intval($fields['dynamic_xml']['cache'])), NULL, array('size' => '6')); $label->setValue('Update cached result every ' . $input->generate(false) . ' minutes'); if (isset($this->_errors['dynamic_xml']['cache'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['dynamic_xml']['cache'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __('static_xml')); $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, General::sanitize($fields['static_xml']), array('class' => 'code'))); if (isset($this->_errors['static_xml'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['static_xml'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Data Source'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', 'Delete'); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this data source'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __form($readonly = false) { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/events/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/events/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array(); $sectionManager = new SectionManager($this->_Parent); if ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $EventManager = new EventManager($this->_Parent); $existing =& $EventManager->create($handle); $about = $existing->about(); if ($this->_context[0] == 'edit' && !$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/events/info/' . $handle . '/'); } $fields['name'] = $about['name']; $fields['source'] = $existing->getSource(); $fields['filters'] = $existing->eParamFILTERS; } if (isset($_POST['fields'])) { $fields = $_POST['fields']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Events'), $about['name']))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); $div = new XMLElement('div'); if (isset($this->_errors['name'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $label = Widget::Label(__('Source')); $sections = $sectionManager->fetch(NULL, 'ASC', 'name'); $options = array(); if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $fields['source'] == $s->get('id'), General::sanitize($s->get('name'))); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context'))); $div = new XMLElement('div'); if (isset($this->_errors['source'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['source'])); } else { $div->appendChild($label); } $group->appendChild($div); $fieldset->appendChild($group); $label = Widget::Label(__('Filter Options')); $filters = is_array($fields['filters']) ? $fields['filters'] : array(); $options = array(array('admin-only', in_array('admin-only', $filters), __('Admin Only')), array('send-email', in_array('send-email', $filters), __('Send Notification Email')), array('expect-multiple', in_array('expect-multiple', $filters), __('Allow Multiple'))); /** * Allows adding of new filter rules to the Event filter rule select box * * @delegate AppendEventFilter * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $options * An array of all the filters that are available, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'options' => &$options)); $label->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); } if ($isEditing) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $doc = $existing->documentation(); $fieldset->setValue('<legend>' . __('Description') . '</legend>' . self::CRLF . General::tabsToSpaces(is_object($doc) ? $doc->generate(true) : $doc, 2)); $this->Form->appendChild($fieldset); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this event'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this event?'))); $div->appendChild($button); } if (!$readonly) { $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); }
function __form() { require_once TOOLKIT . '/class.field.php'; ## Handle unknow context if (!in_array($this->_context[0], array('new', 'edit'))) { $this->_Parent->errorPageNotFound(); } if ($this->_context[0] == 'new' && !$this->_Parent->Author->isDeveloper()) { $this->_Parent->customError(E_USER_ERROR, 'Access Denied', 'You are not authorised to access this page.'); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Author updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Authors</a>', array(DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/system/authors/new/', URL . '/symphony/system/authors/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Author created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Authors</a>', array(DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/system/authors/new/', URL . '/symphony/system/authors/')), Alert::SUCCESS); break; } } $this->setPageType('form'); $isOwner = false; if (isset($_POST['fields'])) { $author = $this->_Author; } elseif ($this->_context[0] == 'edit') { if (!($author_id = $this->_context[1])) { redirect(URL . '/symphony/system/authors/'); } if (!($author = $this->_AuthorManager->fetchByID($author_id))) { $this->_Parent->customError(E_USER_ERROR, 'Author not found', 'The author profile you requested does not exist.'); } } else { $author =& $this->_AuthorManager->create(); } if ($this->_context[0] == 'edit' && $author->get('id') == $this->_Parent->Author->get('id')) { $isOwner = true; } $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Authors'), $author->getFullName()))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $author->getFullName()); ### Essentials ### $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('First Name')); $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name'))); $div->appendChild(isset($this->_errors['first_name']) ? $this->wrapFormElementWithError($label, $this->_errors['first_name']) : $label); $label = Widget::Label(__('Last Name')); $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name'))); $div->appendChild(isset($this->_errors['last_name']) ? $this->wrapFormElementWithError($label, $this->_errors['last_name']) : $label); $group->appendChild($div); $label = Widget::Label(__('Email Address')); $label->appendChild(Widget::Input('fields[email]', $author->get('email'))); $group->appendChild(isset($this->_errors['email']) ? $this->wrapFormElementWithError($label, $this->_errors['email']) : $label); $this->Form->appendChild($group); ### ### Login Details ### $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Login Details'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Username')); $label->appendChild(Widget::Input('fields[username]', $author->get('username'), NULL)); $div->appendChild(isset($this->_errors['username']) ? $this->wrapFormElementWithError($label, $this->_errors['username']) : $label); $label = Widget::Label(__('User Type')); $options = array(array('author', false, __('Author')), array('developer', $author->isDeveloper(), __('Developer'))); $label->appendChild(Widget::Select('fields[user_type]', $options)); $div->appendChild($label); $group->appendChild($div); $div = new XMLElement('div', NULL, array('class' => 'triple group')); if ($this->_context[0] == 'edit') { $div->setAttribute('id', 'change-password'); $label = Widget::Label(__('Old Password')); if (isset($this->_errors['old-password'])) { $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->_errors['old-password'])); } $label->appendChild(Widget::Input('fields[old-password]', NULL, 'password')); $div->appendChild(isset($this->_errors['old-password']) ? $this->wrapFormElementWithError($label, $this->_errors['old-password']) : $label); } $label = Widget::Label($this->_context[0] == 'edit' ? __('New Password') : __('Password')); $label->appendChild(Widget::Input('fields[password]', NULL, 'password')); $div->appendChild(isset($this->_errors['password']) ? $this->wrapFormElementWithError($label, $this->_errors['password']) : $label); $label = Widget::Label($this->_context[0] == 'edit' ? __('Confirm New Password') : __('Confirm Password')); if (isset($this->_errors['password-confirmation'])) { $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->_errors['password-confirmation'])); } $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password')); $div->appendChild($label); $group->appendChild($div); if ($this->_context[0] == 'edit') { $group->appendChild(new XMLElement('p', __('Leave new password field blank to keep the current password'), array('class' => 'help'))); } $label = Widget::Label(); $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox'); if ($author->get('auth_token_active') == 'yes') { $input->setAttribute('checked', 'checked'); } $temp = URL . '/symphony/login/' . $author->createAuthToken() . '/'; $label->setValue(__('%1$s Allow remote login via <a href="%2$s">%2$s</a>', array($input->generate(), $temp))); $group->appendChild($label); $label = Widget::Label(__('Default Section')); $sectionManager = new SectionManager($this->_Parent); $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder'); $options = array(); if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $author->get('default_section') == $s->get('id'), $s->get('name')); } } $label->appendChild(Widget::Select('fields[default_section]', $options)); $group->appendChild($label); $this->Form->appendChild($group); ### $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Author'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit' && !$isOwner) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this author'))); $div->appendChild($button); } $this->Form->appendChild($div); }
function render() { $this->setPageType('form'); $fields = array(); // If we're editing, make sure the item exists if ($this->_context[0]) { if (!($doc_id = $this->_context[0])) { redirect(URL . '/symphony/extension/documenter/manage'); } $existing = Symphony::Database()->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\td.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_documentation` AS d\n\t\t\t\t\tWHERE\n\t\t\t\t\t\td.id = '{$doc_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { $this->_Parent->customError(E_USER_ERROR, __('Documentation Item not found'), __('The documentation item you requested to edit does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found')); } } // Build the status message if (isset($this->_context[1])) { if ($this->_context[1] == 'saved') { $this->pageAlert(__('Documentation Item updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), URL . '/symphony/extension/documenter/new/', URL . '/symphony/extension/documenter/')), Alert::SUCCESS); } else { $this->pageAlert(__('Documentation Item created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), URL . '/symphony/extension/documenter/new/', URL . '/symphony/extension/documenter/')), Alert::SUCCESS); } } // Find values if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { if ($this->_context[0]) { $fields = $existing; $fields['content'] = General::sanitize($fields['content']); } } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } // Start building the page $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Documentation'), $title))); $this->appendSubheading($title ? $title : __('Untitled')); // Start building the fieldsets $this->Form->setAttribute('class', 'two columns'); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary column'); // Title text input $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = Widget::Error($label, $this->_errors['title']); } $fieldset->appendChild($label); // Content textarea $label = Widget::Label(__('Content')); $content = Widget::Textarea('fields[content]', 30, 80, $fields['content']); if (Symphony::Configuration()->get('text-formatter', 'documentation') != 'none') { $content->setAttribute('class', Symphony::Configuration()->get('text-formatter', 'documentation')); } $label->appendChild($content); $fieldset->appendChild(isset($this->_errors['content']) ? Widget::Error($label, $this->_errors['content']) : $label); $fieldset->appendChild(Widget::Input('autogenerate', __('Auto-generate content according to selected section(s)'), 'button', array('class' => 'button'))); $this->Form->appendChild($fieldset); // Pages multi-select $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'secondary column'); $label = Widget::Label(__('Pages')); if (!is_array($fields['pages'])) { $pages_array = explode(',', $fields['pages']); } else { $pages_array = $fields['pages']; } $options = array(); // Generate a list of sectionField-data for auto-generation of documentation: $arr = array(); // Build the options list using the navigation array foreach (Administration::instance()->Page->_navigation as $menu) { $items = array(); foreach ($menu['children'] as $item) { $items[] = array($item['link'], in_array($item['link'], $pages_array), $menu['name'] . " > " . $item['name']); // If it's a section, add New and Edit pages // NOTE: This will likely break when extensions add custom nav groups if ($menu['name'] != 'Blueprints' and $menu['name'] != 'System') { $items[] = array($item['link'] . 'new/', in_array($item['link'] . 'new/', $pages_array), $menu['name'] . " > " . $item['name'] . " New"); $items[] = array($item['link'] . 'edit/', in_array($item['link'] . 'edit/', $pages_array), $menu['name'] . " > " . $item['name'] . " Edit"); } // Generate a list of sectionField-data for auto-generation of documentation: if ($item['type'] == 'section') { $arr2 = array('name' => $item['name'], 'link' => $item['link'], 'items' => array()); $fields = FieldManager::fetch(null, $item['section']['id']); foreach ($fields as $field) { /* @var $field Field */ $arr2['items'][] = array('label' => $field->get('label')); } $arr[] = $arr2; } } $options[] = array('label' => $menu['name'], 'options' => $items); } Administration::instance()->Page->addElementToHead(new XMLElement('script', 'var sectionFields = ' . json_encode($arr) . ';', array('type' => 'text/javascript'))); $label->appendChild(Widget::Select('fields[pages][]', $options, array('multiple' => 'multiple', 'id' => 'documenter-pagelist'))); if (isset($this->_errors['pages'])) { $label = Widget::Error($label, $this->_errors['pages']); } $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Form actions $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] ? __('Save Changes') : __('Document It'), 'submit', array('accesskey' => 's'))); if ($this->_context[0]) { $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 function __viewEdit() { if (!($section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle']))) { Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>'))); } $section = SectionManager::fetch($section_id); $entry_id = intval($this->_context['entry_id']); EntryManager::setFetchSorting('id', 'DESC'); if (!($existingEntry = EntryManager::fetch($entry_id))) { Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.')); } $existingEntry = $existingEntry[0]; // If there is post data floating around, due to errors, create an entry object if (isset($_POST['fields'])) { $fields = $_POST['fields']; $entry =& EntryManager::create(); $entry->set('section_id', $existingEntry->get('section_id')); $entry->set('id', $entry_id); $entry->setDataFromPost($fields, $errors, true); } else { $entry = $existingEntry; if (!$section) { $section = SectionManager::fetch($entry->get('section_id')); } } /** * Just prior to rendering of an Entry edit form. * * @delegate EntryPreRender * @param string $context * '/publish/edit/' * @param Section $section * @param Entry $entry * @param array $fields */ Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields)); if (isset($this->_context['flag'])) { $link = 'publish/' . $this->_context['section_handle'] . '/new/'; list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3); if (isset($_REQUEST['prepopulate'])) { $link .= '?'; foreach ($_REQUEST['prepopulate'] as $field_id => $value) { $link .= "prepopulate[{$field_id}]={$value}&"; } $link = preg_replace("/&\$/", '', $link); } // These flags are only relevant if there are no errors if (empty($this->_errors)) { switch ($flag) { case 'saved': $this->pageAlert(__('Entry updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/' . $link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Entry created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/' . $link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS); break; } } } // Determine the page title $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1"); $field = FieldManager::fetch($field_id); $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id))); if (trim($title) == '') { $title = __('Untitled'); } // Check if there is a field to prepopulate if (isset($_REQUEST['prepopulate'])) { foreach ($_REQUEST['prepopulate'] as $field_id => $value) { $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden')); } } $this->setPageType('form'); $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->Form->setAttribute('class', 'two columns'); $this->setTitle(__('%1$s – %2$s – %3$s', array($title, $section->get('name'), __('Symphony')))); // Only show the Edit Section button if the Author is a developer. #938 ^BA if (Administration::instance()->Author->isDeveloper()) { $this->appendSubheading($title, Widget::Anchor(__('Edit Section'), SYMPHONY_URL . '/blueprints/sections/edit/' . $section_id, __('Edit Section Configuration'), 'button')); } else { $this->appendSubheading($title); } $this->insertBreadcrumbs(array(Widget::Anchor($section->get('name'), SYMPHONY_URL . '/publish/' . $this->_context['section_handle']))); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden')); $primary = new XMLElement('fieldset'); $primary->setAttribute('class', 'primary column'); $sidebar_fields = $section->fetchFields(NULL, 'sidebar'); $main_fields = $section->fetchFields(NULL, 'main'); if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) { $message = __('Fields must be added to this section before an entry can be created.'); if (Administration::instance()->Author->isDeveloper()) { $message .= ' <a href="' . SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/" accesskey="c">' . __('Add fields') . '</a>'; } $this->pageAlert($message, Alert::ERROR); } else { if (is_array($main_fields) && !empty($main_fields)) { foreach ($main_fields as $field) { $primary->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($primary); } if (is_array($sidebar_fields) && !empty($sidebar_fields)) { $sidebar = new XMLElement('fieldset'); $sidebar->setAttribute('class', 'secondary column'); foreach ($sidebar_fields as $field) { $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($sidebar); } $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' => 'button confirm delete', 'title' => __('Delete this entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?'))); $div->appendChild($button); $this->Form->appendChild($div); } }