public static function init()
 {
     if (REST_API::getOutputFormat() == 'csv') {
         REST_API::sendError(sprintf('%s output format not supported.', strtoupper(REST_API::getOutputFormat())), 401, 'xml');
     }
     $request_uri = REST_API::getRequestURI();
     $section_reference = $request_uri[0];
     $sections = NULL;
     if (is_null($section_reference)) {
         $sections = SectionManager::fetch();
     } elseif (is_numeric($section_reference)) {
         $sections = SectionManager::fetch($section_reference);
     } else {
         $section_id = SectionManager::fetchIDFromHandle($section_reference);
         if ($section_id) {
             $sections = SectionManager::fetch($section_id);
         }
     }
     if (!is_array($sections)) {
         $sections = array($sections);
     }
     if (!reset($sections) instanceof Section) {
         REST_API::sendError(sprintf("Section '%s' not found.", $section_reference), 404);
     }
     self::$_sections = $sections;
 }
 public function initaliseAdminPageHead($context)
 {
     $page = Administration::instance()->Page;
     if ($page instanceof contentPublish) {
         $callback = Administration::instance()->getPageCallback();
         if ($callback['context']['page'] !== 'edit') {
             return;
         }
         $sm = new SectionManager(Administration::instance());
         $current_section = $sm->fetch($sm->fetchIDFromHandle($callback['context']['section_handle']));
         $current_section_hash = $this->serialiseSectionSchema($current_section);
         $duplicate_sections = array();
         foreach ($sm->fetch() as $section) {
             $section_hash = $this->serialiseSectionSchema($section);
             if ($section_hash == $current_section_hash && $section->get('handle')) {
                 $duplicate_sections[$section->get('handle')] = $section->get('name');
             }
         }
         if (count($duplicate_sections) < 2) {
             $duplicate_sections = NULL;
         }
         Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('duplicate-entry', " . json_encode(array('current-section' => $callback['context']['section_handle'], 'duplicate-sections' => $duplicate_sections)) . ");", array('type' => 'text/javascript')), time());
         $page->addScriptToHead(URL . '/extensions/duplicate_entry/assets/duplicate_entry.js', 10001);
         // add particular css for SSM
         Administration::instance()->Page->addElementToHead(new XMLElement('style', "body.inline.subsection #duplicate-entry { display: none; visibility: collapse }", array('type' => 'text/css')), time() + 101);
     }
 }
 public static function init()
 {
     if (REST_API::getOutputFormat() == 'csv' && !REST_API::getHTTPMethod() == 'get') {
         REST_API::sendError(sprintf('%s output format not supported for %s requests.', strtoupper(REST_API::getOutputFormat()), strtoupper(REST_API::getHTTPMethod())), 401, 'xml');
     }
     $request_uri = REST_API::getRequestURI();
     self::$_section_handle = $request_uri[0];
     self::$_entry_id = $request_uri[1];
     $section_id = SectionManager::fetchIDFromHandle(self::$_section_handle);
     if (!$section_id) {
         REST_API::sendError('Section not found.', 404);
     }
     self::$_section_id = $section_id;
     self::setDatasourceParam('included_elements', $_REQUEST['fields']);
     self::setDatasourceParam('limit', $_REQUEST['limit']);
     self::setDatasourceParam('page', $_REQUEST['page']);
     self::setDatasourceParam('sort', $_REQUEST['sort']);
     self::setDatasourceParam('order', $_REQUEST['order']);
     self::setDatasourceParam('groupby', $_REQUEST['groupby']);
     $filters = $_REQUEST['filter'];
     if (!is_null($filters) && !is_array($filters)) {
         $filters = array($filters);
     }
     self::setDatasourceParam('filters', $filters);
 }
 public static function hasInstance($ext_name = NULL, $section_handle)
 {
     $sid = SectionManager::fetchIDFromHandle($section_handle);
     $section = SectionManager::fetch($sid);
     $fm = $section->fetchFields($ext_name);
     return is_array($fm) && !empty($fm);
 }
Example #5
0
 public function __viewIndex()
 {
     $sm = new SectionManager($this->_Parent);
     $section = $sm->fetch($sm->fetchIDFromHandle($_GET['section']));
     $field_id = $_GET['field'];
     $fields = $section->fetchFields();
     foreach ($fields as $field) {
         if ($field->get('id') == $field_id) {
             $upload_field = $field;
         }
     }
     if (!$upload_field) {
         die('0|Invalid Field ID');
     }
     $status = $upload_field->checkPostFieldData($_FILES['Filedata'], $message);
     if ($status != Field::__OK__) {
         die($status . '|' . $message);
     }
     $processData = $upload_field->processRawFieldData($_FILES['Filedata'], $status, $message);
     if ($status != Field::__OK__) {
         die($status . '|' . $message);
     }
     echo Field::__OK__ . '|' . $processData['file'];
     die;
 }
Example #6
0
 public function initializeAdmin($context)
 {
     $page = Administration::instance()->Page;
     $context = $page->getContext();
     $callback = Administration::instance()->getPageCallback();
     // only proceed on New or Edit publish pages
     if ($page instanceof contentPublish and in_array($context['page'], array('new', 'edit'))) {
         $page->addStylesheetToHead(URL . '/extensions/publish_tabs/assets/publish_tabs.publish.css', 'screen', 9001);
         $page->addScriptToHead(URL . '/extensions/publish_tabs/assets/publish_tabs.publish.js', 9002);
         include_once TOOLKIT . '/class.sectionmanager.php';
         $section_id = SectionManager::fetchIDFromHandle($callback['context']['section_handle']);
         $section = SectionManager::fetch($section_id);
         if (!$section instanceof Section) {
             return;
         }
         $tabs = array();
         $current_tab = '';
         $index = -1;
         foreach ($section->fetchFieldsSchema() as $i => $field) {
             if ($i == 0 && $field['type'] != 'publish_tabs') {
                 $current_tab = 'untitled-tab';
                 $tabs[++$index]['tab_id'] = $current_tab;
             }
             if ($field['type'] == 'publish_tabs') {
                 $current_tab = $field['id'];
                 $tabs[++$index]['tab_id'] = $current_tab;
             } else {
                 $tabs[$index][$field['location']][] = 'field-' . $field['id'];
             }
         }
         $page->addElementToHead(new XMLElement('script', "Symphony.Context.add('publish-tabs', " . json_encode($tabs) . ")", array('type' => 'text/javascript')), 9003);
     }
 }
 public function getSectionId()
 {
     $sectionManager = new SectionManager(Frontend::instance());
     $section_id = $sectionManager->fetchIDFromHandle(General::sanitize($_REQUEST['MUUsource']));
     if (!($section = $sectionManager->fetch($section_id))) {
         return NULL;
     } else {
         return $section_id;
     }
 }
 public static function findSection($handle)
 {
     if (!is_numeric($handle)) {
         $handle = SectionManager::fetchIDFromHandle($handle);
     }
     $ret = SectionManager::fetch($handle);
     if (!is_object($ret)) {
         self::throwEx('Section does not exist');
     }
     return $ret;
 }
 public function initaliseAdminPageHead($context)
 {
     $page = $context['oPage'];
     $assets_path = '/extensions/massuploadutility/assets/';
     // to check if it's an excluded section
     $section_id = SectionManager::fetchIDFromHandle($page->_context['section_handle']);
     if ($page instanceof contentPublish and $page->_context['page'] == 'new' and $this->validateSection($section_id) and $this->validateUser()) {
         Administration::instance()->Page->addStylesheetToHead(URL . $assets_path . 'massuploadutility.css', 'screen', 14145);
         Administration::instance()->Page->addScriptToHead(URL . $assets_path . 'massuploadutility.publish.js', 14156);
         Administration::instance()->Page->addScriptToHead(URL . $assets_path . 'jquery.html5_upload.js', 14156);
     }
 }
 public function appendScripts($context)
 {
     $callback = $context['parent']->getPageCallback();
     if (in_array($callback['driver'], array('blueprintspages', 'blueprintsutilities'))) {
         $context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zen_textarea.min.js', 1000, false);
     }
     if ($callback['driver'] == 'publish') {
         $sectionManager = new SectionManager($context['parent']);
         $section_id = $sectionManager->fetchIDFromHandle($callback['context']['section_handle']);
         if ($this->__isAllowedSection($section_id)) {
             $context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zen_textarea.min.js', 1000, false);
         }
     }
 }
Example #11
0
 public function __viewIndex()
 {
     header('content-type: text/javascript');
     $sm = new SectionManager($this->_Parent);
     $section_id = $sm->fetchIDFromHandle($_GET['section']);
     $section = $sm->fetch($section_id);
     $em = new EntryManager($this->_Parent);
     $entry_id = $_GET['entry'];
     $e = $em->fetch($entry_id);
     $fields = array();
     $data = $e[0]->getData();
     foreach ($section->fetchFieldsSchema() as $field) {
         // Set field names and take strange date field name into account
         $field['element_name'] = $field['type'] == 'date' ? 'fields[' . $field['element_name'] . ']' . $field['element_name'] : 'fields[' . $field['element_name'] . ']';
         // Populate field elements with value, depending on field type
         switch ($field['type']) {
             case 'author':
                 $fields[$field['element_name']] = $data[$field['id']]['author_id'];
                 break;
             case 'upload':
                 $fields[$field['element_name']] = $data[$field['id']]['file'];
                 break;
             case 'selectbox_link':
                 $fields[$field['element_name']] = $data[$field['id']]['relation_id'];
                 break;
             case 'input':
             case 'textarea':
             case 'taglist':
             case 'select':
             case 'checkbox':
             case 'date':
             case 'order_entries':
                 $fields[$field['element_name']] = $data[$field['id']]['value'];
                 break;
             default:
                 if (!empty($data[$field['id']]['value'])) {
                     $fields[$field['element_name']] = $data[$field['id']]['value'];
                 } else {
                     // Fall back on first array element
                     // Add field type to switch for accurate specification
                     $fields[$field['element_name']] = $data[$field['id']][0];
                 }
                 break;
         }
     }
     echo 'jQuery(document).ready(function() { jQuery(\'form\').populate(' . json_encode($fields) . ")});\n";
     exit;
 }
 public function dAdminPagePreGenerate($context)
 {
     $callback = Administration::instance()->getPageCallback();
     if ($callback['context']['page'] === 'edit') {
         /** @var $cxt XMLElement */
         $cxt = $context['oPage']->Context;
         if (!$cxt instanceof XMLElement) {
             return;
         }
         $actions = $cxt->getChildByName('ul', 0);
         // append list of actions if missing
         if (!$actions instanceof XMLElement) {
             $ul = new XMLelement('ul', null, array('class' => 'actions'));
             $cxt->appendChild($ul);
             $actions = $cxt->getChildByName('ul', 0);
         }
         // fetch entries
         $section_id = SectionManager::fetchIDFromHandle($callback['context']['section_handle']);
         $section = SectionManager::fetch($section_id);
         EntryManager::setFetchSorting($section->getSortingField(), $section->getSortingOrder());
         $entries = EntryManager::fetch(null, $section_id, null, null, null, null, null, false, false);
         // get next and prev
         $entry_id = $prev_id = $next_id = $callback['context']['entry_id'];
         $count = count($entries);
         for ($i = 0; $i < $count; $i++) {
             if ($entries[$i]['id'] == $entry_id) {
                 $prev_id = $i == 0 ? $entries[$count - 1]['id'] : $entries[$i - 1]['id'];
                 $next_id = $i == $count - 1 ? $entries[0]['id'] : $entries[$i + 1]['id'];
                 break;
             }
         }
         if ($prev_id == $entry_id && $next_id == $entry_id) {
             return;
         }
         // add buttons
         $li = new XMLelement('li', null, array('class' => 'entry-nav'));
         if ($prev_id !== $entry_id) {
             $li->appendChild(Widget::Anchor(__('&larr; Previous'), SYMPHONY_URL . $callback['pageroot'] . 'edit/' . $prev_id, null, 'button entry-nav-prev', null, array('accesskey' => 'z')));
         }
         if ($next_id !== $entry_id) {
             $li->appendChild(Widget::Anchor(__('Next &rarr;'), SYMPHONY_URL . $callback['pageroot'] . 'edit/' . $next_id, null, 'button entry-nav-next', null, array('accesskey' => 'x')));
         }
         $actions->appendChild($li);
     }
 }
Example #13
0
 /**
  * Get a Section object from a handle or ID. If section is not found, returns null
  *
  * @param $section (optional) - section handle or ID. If null, section handle will be taken form $callback
  *
  * @return null|Section
  */
 public static function getSection($section = null)
 {
     if ($section instanceof Section) {
         return $section;
     }
     if ($section === null) {
         $callback = Administration::instance()->getPageCallback();
         if (!isset($callback['context']['section_handle'])) {
             return null;
         }
         $section = $callback['context']['section_handle'];
     }
     $section_id = is_numeric($section) ? $section : SectionManager::fetchIDFromHandle($section);
     $s = SectionManager::fetch($section_id);
     if (!$s instanceof Section) {
         return null;
     }
     return $s;
 }
 public function __viewIndex()
 {
     header('content-type: text/javascript');
     $sm = new SectionManager($this->_Parent);
     $section_id = $sm->fetchIDFromHandle($_GET['section']);
     $section = $sm->fetch($section_id);
     $fields = array();
     foreach ($section->fetchFilterableFields() as $field) {
         $html = new XMLElement('html');
         $field->displayPublishPanel($html);
         $dom = new DomDocument();
         $dom->loadXML($html->generate());
         $xpath = new DomXPath($dom);
         $count = 0;
         // if the generated HTML contains a file upload element
         foreach ($xpath->query("//*[name()='input' and @type='file']") as $file) {
             $fields[$field->get('element_name')]['section'] = $_GET['section'];
             $fields[$field->get('element_name')]['field_id'] = $field->get('id');
             $fields[$field->get('element_name')]['handle'] = $field->get('element_name');
             $fields[$field->get('element_name')]['destination'] = $field->get('destination');
             // if a validator regular expression has been set we need to parse and explode into Uploadify syntax
             if ($field->get('validator')) {
                 $validator = str_replace('$/i', '', $field->get('validator'));
                 $validator = trim($validator, '():?[]\\/.');
                 $validator = explode('|', $validator);
                 foreach ($validator as $type) {
                     if ($type == 'jpe?g') {
                         $fields[$field->get('element_name')]['types'] .= '*.jpg;*.jpeg;';
                     } else {
                         $fields[$field->get('element_name')]['types'] .= '*.' . $type . ';';
                     }
                 }
                 $fields[$field->get('element_name')]['types'] = trim($fields[$field->get('element_name')]['types'], ';');
             } else {
                 $fields[$field->get('element_name')]['types'] = '*.*';
             }
         }
     }
     echo 'var upload_fields = ', json_encode($fields), ";\n";
     echo 'var PHPSESSID = "', session_id(), "\";\n";
     exit;
 }
Example #15
0
 public function adminPagePostCallback($context)
 {
     // check if logged in
     if (!Administration::instance()->isLoggedIn()) {
         return;
     }
     // check driver
     if ($context['callback']['driver'] !== 'publish') {
         return;
     }
     // get context
     $page = $context['callback']['context']['page'];
     $section = $context['callback']['context']['section_handle'];
     // check section
     if (!($section = SectionManager::fetchIDFromHandle($section))) {
         return;
     }
     if (!($section = SectionManager::fetch($section))) {
         return;
     }
     // check setting
     if ($section->get('single') !== 'yes') {
         return;
     }
     // set flag
     $this->single = true;
     // check page
     if ($page === 'edit') {
         return;
     }
     // check entries
     if ($entries = EntryManager::fetch(null, $section->get('id'), 1, 0)) {
         // set entry
         $context['callback']['context']['entry_id'] = current($entries)->get('id');
         // reroute
         $context['callback']['context']['page'] = 'edit';
     } else {
         // reroute
         $context['callback']['context']['page'] = 'new';
     }
 }
Example #16
0
    public function initaliseAdminPageHead($context)
    {
        $page = $context['parent']->Page;
        if ($page instanceof contentExtensionBulkImporterImport) {
            $page->addStylesheetToHead(URL . '/extensions/bulkimporter/assets/bulkimporter.import.css', 'screen', 100);
            $page->addScriptToHead(URL . '/extensions/bulkimporter/assets/bulkimporter.import.js', 101);
        } else {
            $callback = Symphony::Engine()->getPageCallback();
            if (!is_array($callback['context'])) {
                return;
            }
            if ($callback['driver'] == 'publish' && !empty($callback['context']['section_handle']) && !empty($callback['context']['entry_id'])) {
                $sm = new SectionManager(Symphony::Engine());
                $section_id = $sm->fetchIDFromHandle($callback['context']['section_handle']);
                $values = Symphony::Database()->fetch('
						SELECT *
						FROM tbl_bulkimporter_fields
						WHERE `section_id` = ' . intval($section_id), 'field_id');
                if (!empty($values)) {
                    Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('bulkimporter', " . json_encode(array('fields' => $values)) . ");", array('type' => 'text/javascript')), 100);
                    $page->addStylesheetToHead(URL . '/extensions/bulkimporter/assets/bulkimporter.publish.css', 'screen', 200);
                    $page->addScriptToHead(URL . '/extensions/bulkimporter/assets/bulkimporter.publish.js', 201);
                }
            } else {
                if ($callback['driver'] == 'blueprintssections') {
                    if ($callback['context'][0] == 'edit' && is_numeric($callback['context'][1])) {
                        $values = Symphony::Database()->fetch('
							SELECT *
							FROM tbl_bulkimporter_fields
							WHERE `section_id` = ' . intval($callback['context'][1]), 'field_id');
                        if (!empty($values)) {
                            Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('bulkimporter', " . json_encode(array('fields' => $values)) . ");", array('type' => 'text/javascript')), 100);
                        }
                    }
                    //$page->addStylesheetToHead(URL . '/extensions/bulkimporter/assets/bulkimporter.settings.css','screen', 200);
                    $page->addScriptToHead(URL . '/extensions/bulkimporter/assets/bulkimporter.settings.js', 201);
                }
            }
        }
    }
 public function __viewIndex()
 {
     header('content-type: text/javascript');
     $sm = new SectionManager($this->_Parent);
     $section_id = $sm->fetchIDFromHandle($_GET['section']);
     $section = $sm->fetch($section_id);
     $fields = array();
     foreach ($section->fetchFilterableFields() as $field) {
         $fields[$field->get('label')]['handle'] = $field->get('element_name');
         $html = new XMLElement('html');
         $field->displayPublishPanel($html);
         $dom = new DomDocument();
         $dom->loadXML($html->generate());
         $xpath = new DomXPath($dom);
         $count = 0;
         foreach ($xpath->query("//*[name()='option'] | //*[name()='li']") as $option) {
             $value = '';
             if ($option->getAttribute('value')) {
                 $value = $option->getAttribute('value');
             } else {
                 $value = $option->nodeValue;
             }
             if ($value != '') {
                 $fields[$field->get('label')]['options'][$count]['label'] = $option->nodeValue;
                 $fields[$field->get('label')]['options'][$count]['value'] = $value;
                 $count++;
             }
         }
         if ($field->get('type') == 'checkbox') {
             $fields[$field->get('label')]['options'][] = 'Yes';
             $fields[$field->get('label')]['options'][] = 'No';
         }
     }
     echo 'var filters = ', json_encode($fields), ";\n";
     echo "var filters_label = \"\";\n";
     echo 'var filters_apply = "', __('Apply'), "\";\n";
     echo 'var filters_clear = "', __('Clear'), "\";\n";
     exit;
 }
 public function view()
 {
     $handle = General::sanitize($_GET['handle']);
     $section = General::sanitize($_GET['section']);
     $options = array();
     $filters = array();
     if (!empty($handle) && !empty($section)) {
         $section_id = SectionManager::fetchIDFromHandle($section);
         $field_id = FieldManager::fetchFieldIDFromElementName($handle, $section_id);
         $field = FieldManager::fetch($field_id);
         if (!empty($field) && $field->canPublishFilter() === true) {
             if (method_exists($field, 'getToggleStates')) {
                 $options = $field->getToggleStates();
             } elseif (method_exists($field, 'findAllTags')) {
                 $options = $field->findAllTags();
             }
         }
     }
     foreach ($options as $value => $data) {
         $filters[] = array('value' => $value ? $value : $data, 'text' => $data ? $data : $value);
     }
     $this->_Result['filters'] = $filters;
 }
 /**
  * Process the page's parameters.  This is used to extract the page id
  * and set the associated data source to the id of the Page Fields section
  * for it.
  *
  * @param array env The parameters.
  */
 function processParameters($env = NULL)
 {
     // Get the handle of the PF section associated with the page.
     //
     $pageId = $env['param']['current-page-id'];
     $pageFieldsSectionHandle = Lang::createHandle(PF_SECTION_TITLE_PREFIX . $pageId);
     // Retrieve and store the Id of the section so we can return it from getSource()
     //
     $sectionManager = new SectionManager($this->_Parent);
     $this->pageFieldsSectionId = $sectionManager->fetchIDFromHandle($pageFieldsSectionHandle);
     // Initialise $dsParamINCLUDEDELEMENTS with the names of all fields for the section.
     //
     $fieldNames = $this->_Parent->Database->fetchCol('element_name', "SELECT `element_name` FROM `tbl_fields` WHERE `parent_section` = '{$this->pageFieldsSectionId}'");
     $this->dsParamINCLUDEDELEMENTS = array();
     if (is_array($fieldNames) && !empty($fieldNames)) {
         foreach ($fieldNames as $elementName) {
             $this->dsParamINCLUDEDELEMENTS[] = $elementName;
         }
     }
     // Call parent class implementation.
     //
     parent::processParameters($env);
 }
 public function __refresh($context)
 {
     /*
     	Cear the DS cache when its associated Section is edited
     */
     $sm = new SectionManager($this->_Parent);
     $section_handle = Administration::instance()->Page->_context['section_handle'];
     $section_id = $sm->fetchIDFromHandle($section_handle);
     // find all native data sources (not added via Extensions)
     $dsm = new DatasourceManager($this->_Parent);
     $datasources = $dsm->listAll();
     if (is_array($datasources) && !empty($datasources)) {
         foreach ($datasources as $ds) {
             // check they are "Section" DSs and not Dynamic/Static XML, Authors or Navigation
             if (is_numeric($ds['type']) && $ds['type'] == $section_id) {
                 // instantiate the DS class and see if it has caching enabled
                 $datasource = $dsm->create($ds['handle']);
                 if ($datasource->dsParamCACHE) {
                     $this->clearCache(array($ds['handle']));
                 }
             }
         }
     }
 }
 /**
  * Prepare publish index for manual entry ordering
  */
 public function prepareIndex($context)
 {
     $callback = Symphony::Engine()->getPageCallback();
     if ($callback['driver'] == 'publish' && $callback['context']['page'] == 'index') {
         // Fetch sort settings for this section (sort field ID and direction)
         $section_id = SectionManager::fetchIDFromHandle($callback['context']['section_handle']);
         // Fetch sorting field
         if ($section_id) {
             $section = SectionManager::fetch($section_id);
             $field = FieldManager::fetch($section->getSortingField());
             // Check sorting field
             if ($field && $field->get('type') == 'order_entries') {
                 $this->force_sort = $field->get('force_sort');
                 $this->field_id = $field->get('id');
                 $this->direction = $section->getSortingOrder();
                 // Initialise manual ordering
                 $this->addComponents();
                 if ($field->get('disable_pagination') == 'yes') {
                     $this->disablePagination();
                 }
             }
         }
     }
 }
 public function appendScriptToHead($context)
 {
     $page_callback = Administration::instance()->getPageCallback();
     $page_callback = $page_callback['context'];
     if (isset($page_callback['section_handle']) && $page_callback['page'] == 'index') {
         // find sort settings for this section (sort field ID and direction)
         $section_id = SectionManager::fetchIDFromHandle($page_callback['section_handle']);
         if (!$section_id) {
             return;
         }
         $section = SectionManager::fetch(SectionManager::fetchIDFromHandle($page_callback['section_handle']));
         // we only want a valid entry order field and ascending order only
         if ($section->getSortingOrder() !== 'asc' || !is_numeric($section->getSortingField())) {
             return;
         }
         $field = FieldManager::fetch($section->getSortingField());
         if ($field->get('type') !== 'order_entries') {
             return;
         }
         Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('order-entries', " . json_encode(array('id' => $field->get('id'), 'force-sort' => $field->get('force_sort'))) . ");", array('type' => 'text/javascript')), time());
         Administration::instance()->Page->addScriptToHead(URL . '/extensions/order_entries/assets/order_entries.publish.js', time());
         Symphony::Configuration()->set("pagination_maximum_rows", 99999, "symphony");
     }
 }
 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}&amp;";
             }
             $link = preg_replace("/&amp;\$/", '', $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 &ndash; %2$s &ndash; %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);
     }
 }
Example #24
0
 function __viewEdit()
 {
     $sectionManager = new SectionManager($this->_Parent);
     if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
         $this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle'])), false, true);
     }
     $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))) {
         $this->_Parent->customError(E_USER_ERROR, __('Unknown Entry'), __('The entry you are looking for could not be found.'), false, true);
     }
     $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'));
         }
     }
     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}";
         }
         switch ($flag) {
             case 'saved':
                 $this->pageAlert(__('Entry updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Entry created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
                 break;
         }
     }
     ### Determine the page title
     $field_id = $this->_Parent->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';
     }
     $this->setPageType('form');
     $this->Form->setAttribute('enctype', 'multipart/form-data');
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array(__('Symphony'), $section->get('name'), $title)));
     $this->appendSubheading($title);
     $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', $this->_Parent->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 your trying to create an entry. Perhaps you want custom fields first? <a href="%s">Click here to create some.</a>', array(URL . '/symphony/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' => 'confirm delete', 'title' => __('Delete this entry')));
     $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 &ndash; %2$s &ndash; %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 __viewEdit()
 {
     if (!($section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle']))) {
         Administration::instance()->throwCustomError(__('The Section, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>')), __('Unknown Section'), Page::HTTP_STATUS_NOT_FOUND);
     }
     $section = SectionManager::fetch($section_id);
     $entry_id = intval($this->_context['entry_id']);
     $base = '/publish/' . $this->_context['section_handle'] . '/';
     $new_link = $base . 'new/';
     $filter_link = $base;
     EntryManager::setFetchSorting('id', 'DESC');
     if (!($existingEntry = EntryManager::fetch($entry_id))) {
         Administration::instance()->throwCustomError(__('Unknown Entry'), __('The Entry, %s, could not be found.', array($entry_id)), Page::HTTP_STATUS_NOT_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('id', $entry_id);
         $entry->set('author_id', $existingEntry->get('author_id'));
         $entry->set('section_id', $existingEntry->get('section_id'));
         $entry->set('creation_date', $existingEntry->get('creation_date'));
         $entry->set('modification_date', $existingEntry->get('modification_date'));
         $entry->setDataFromPost($fields, $errors, true);
         // Editing an entry, so need to create some various objects
     } else {
         $entry = $existingEntry;
         $fields = array();
         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));
     // Iterate over the `prepopulate` parameters to build a URL
     // to remember this state for Create New, View all Entries and
     // Breadcrumb links. If `prepopulate` doesn't exist, this will
     // just use the standard pages (ie. no filtering)
     if (isset($_REQUEST['prepopulate'])) {
         $new_link .= $this->getPrepopulateString();
         $filter_link .= $this->getFilterString();
     }
     if (isset($this->_context['flag'])) {
         // These flags are only relevant if there are no errors
         if (empty($this->_errors)) {
             $time = Widget::Time();
             switch ($this->_context['flag']) {
                 case 'saved':
                     $message = __('Entry updated at %s.', array($time->generate()));
                     break;
                 case 'created':
                     $message = __('Entry created at %s.', array($time->generate()));
             }
             $this->pageAlert($message . ' <a href="' . SYMPHONY_URL . $new_link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . $filter_link . '" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS);
         }
     }
     // Determine the page title
     $field_id = Symphony::Database()->fetchVar('id', 0, sprintf("\n            SELECT `id`\n            FROM `tbl_fields`\n            WHERE `parent_section` = %d\n            ORDER BY `sortorder` LIMIT 1", $section->get('id')));
     if (!is_null($field_id)) {
         $field = FieldManager::fetch($field_id);
     }
     if ($field) {
         $title = $field->prepareReadableValue($existingEntry->getData($field->get('id')), $entry_id, true);
     } else {
         $title = '';
     }
     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->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array($title, $section->get('name'), __('Symphony'))));
     $sidebar_fields = $section->fetchFields(null, 'sidebar');
     $main_fields = $section->fetchFields(null, 'main');
     if (!empty($sidebar_fields) && !empty($main_fields)) {
         $this->Form->setAttribute('class', 'two columns');
     } else {
         $this->Form->setAttribute('class', 'columns');
     }
     // Only show the Edit Section button if the Author is a developer. #938 ^BA
     if (Symphony::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 . (isset($filter_link) ? $filter_link : $base))));
     $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');
     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 (Symphony::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);
         // Create a Drawer for Associated Sections
         $this->prepareAssociationsDrawer($section);
     }
 }
 public function __actionNew()
 {
     if (@array_key_exists('save', $_POST['action']) || @array_key_exists('done', $_POST['action'])) {
         $canProceed = true;
         $edit = $this->_context[0] == "edit";
         $this->_errors = array();
         $fields = isset($_POST['fields']) ? $_POST['fields'] : array();
         $meta = $_POST['meta'];
         if ($edit) {
             $section_id = $this->_context[1];
             $existing_section = SectionManager::fetch($section_id);
         }
         // Check to ensure all the required section fields are filled
         if (!isset($meta['name']) || strlen(trim($meta['name'])) == 0) {
             $this->_errors['name'] = __('This is a required field.');
             $canProceed = false;
         } elseif ($edit) {
             $s = SectionManager::fetchIDFromHandle(Lang::createHandle($meta['name']));
             if ($meta['name'] !== $existing_section->get('name') && !is_null($s) && $s !== $section_id) {
                 $this->_errors['name'] = __('A Section with the name %s already exists', array('<code>' . $meta['name'] . '</code>'));
                 $canProceed = false;
             }
         } elseif (!is_null(SectionManager::fetchIDFromHandle(Lang::createHandle($meta['name'])))) {
             $this->_errors['name'] = __('A Section with the name %s already exists', array('<code>' . $meta['name'] . '</code>'));
             $canProceed = false;
         }
         // Check to ensure all the required section fields are filled
         if (!isset($meta['navigation_group']) || strlen(trim($meta['navigation_group'])) == 0) {
             $this->_errors['navigation_group'] = __('This is a required field.');
             $canProceed = false;
         }
         // Basic custom field checking
         if (is_array($fields) && !empty($fields)) {
             // Check for duplicate CF names
             if ($canProceed) {
                 $name_list = array();
                 foreach ($fields as $position => $data) {
                     if (trim($data['element_name']) == '') {
                         $data['element_name'] = $fields[$position]['element_name'] = $_POST['fields'][$position]['element_name'] = Lang::createHandle($data['label'], 255, '-', false, true, array('@^[\\d-]+@i' => ''));
                     }
                     if (trim($data['element_name']) != '' && in_array($data['element_name'], $name_list)) {
                         $this->_errors[$position] = array('element_name' => __('A field with this handle already exists. All handle must be unique.'));
                         $canProceed = false;
                         break;
                     }
                     $name_list[] = $data['element_name'];
                 }
             }
             if ($canProceed) {
                 $unique = array();
                 foreach ($fields as $position => $data) {
                     $field = FieldManager::create($data['type']);
                     $field->setFromPOST($data);
                     if (isset($existing_section)) {
                         $field->set('parent_section', $existing_section->get('id'));
                     }
                     if ($field->mustBeUnique() && !in_array($field->get('type'), $unique)) {
                         $unique[] = $field->get('type');
                     } elseif ($field->mustBeUnique() && in_array($field->get('type'), $unique)) {
                         // Warning. cannot have 2 of this field!
                         $canProceed = false;
                         $this->_errors[$position] = array('label' => __('There is already a field of type %s. There can only be one per section.', array('<code>' . $field->handle() . '</code>')));
                     }
                     $errors = array();
                     if (Field::__OK__ != $field->checkFields($errors, false) && !empty($errors)) {
                         $this->_errors[$position] = $errors;
                         $canProceed = false;
                     }
                 }
             }
         }
         if ($canProceed) {
             $meta['handle'] = Lang::createHandle($meta['name']);
             // If we are creating a new Section
             if (!$edit) {
                 $meta['sortorder'] = SectionManager::fetchNextSortOrder();
                 /**
                  * Just prior to saving the Section settings. Use with caution as
                  * there is no additional processing to ensure that Field's or Section's
                  * are unique.
                  *
                  * @delegate SectionPreCreate
                  * @since Symphony 2.2
                  * @param string $context
                  * '/blueprints/sections/'
                  * @param array $meta
                  *  The section's settings, passed by reference
                  * @param array $fields
                  *  An associative array of the fields that will be saved to this
                  *  section with the key being the position in the Section Editor
                  *  and the value being a Field object, passed by reference
                  */
                 Symphony::ExtensionManager()->notifyMembers('SectionPreCreate', '/blueprints/sections/', array('meta' => &$meta, 'fields' => &$fields));
                 if (!($section_id = SectionManager::add($meta))) {
                     $this->pageAlert(__('An unknown database occurred while attempting to create the section.'), Alert::ERROR);
                 }
             } else {
                 $meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no';
                 /**
                  * Just prior to updating the Section settings. Use with caution as
                  * there is no additional processing to ensure that Field's or Section's
                  * are unique.
                  *
                  * @delegate SectionPreEdit
                  * @since Symphony 2.2
                  * @param string $context
                  * '/blueprints/sections/'
                  * @param integer $section_id
                  *  The Section ID that is about to be edited.
                  * @param array $meta
                  *  The section's settings, passed by reference
                  * @param array $fields
                  *  An associative array of the fields that will be saved to this
                  *  section with the key being the position in the Section Editor
                  *  and the value being a Field object, passed by reference
                  */
                 Symphony::ExtensionManager()->notifyMembers('SectionPreEdit', '/blueprints/sections/', array('section_id' => $section_id, 'meta' => &$meta, 'fields' => &$fields));
                 if (!SectionManager::edit($section_id, $meta)) {
                     $canProceed = false;
                     $this->pageAlert(__('An unknown database occurred while attempting to create the section.'), Alert::ERROR);
                 }
             }
             if ($section_id && $canProceed) {
                 if ($edit) {
                     // Delete missing CF's
                     $id_list = array();
                     if (is_array($fields) && !empty($fields)) {
                         foreach ($fields as $position => $data) {
                             if (isset($data['id'])) {
                                 $id_list[] = $data['id'];
                             }
                         }
                     }
                     $missing_cfs = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '{$section_id}' AND `id` NOT IN ('" . @implode("', '", $id_list) . "')");
                     if (is_array($missing_cfs) && !empty($missing_cfs)) {
                         foreach ($missing_cfs as $id) {
                             FieldManager::delete($id);
                         }
                     }
                 }
                 // Save each custom field
                 if (is_array($fields) && !empty($fields)) {
                     foreach ($fields as $position => $data) {
                         $field = FieldManager::create($data['type']);
                         $field->setFromPOST($data);
                         $field->set('sortorder', (string) $position);
                         $field->set('parent_section', $section_id);
                         $newField = !(bool) $field->get('id');
                         $field->commit();
                         $field_id = $field->get('id');
                         if ($field_id) {
                             if ($newField) {
                                 /**
                                  * After creation of a Field.
                                  *
                                  * @delegate FieldPostCreate
                                  * @param string $context
                                  * '/blueprints/sections/'
                                  * @param Field $field
                                  *  The Field object, passed by reference
                                  * @param array $data
                                  *  The settings for ths `$field`, passed by reference
                                  */
                                 Symphony::ExtensionManager()->notifyMembers('FieldPostCreate', '/blueprints/sections/', array('field' => &$field, 'data' => &$data));
                             } else {
                                 /**
                                  * After editing of a Field.
                                  *
                                  * @delegate FieldPostEdit
                                  * @param string $context
                                  * '/blueprints/sections/'
                                  * @param Field $field
                                  *  The Field object, passed by reference
                                  * @param array $data
                                  *  The settings for ths `$field`, passed by reference
                                  */
                                 Symphony::ExtensionManager()->notifyMembers('FieldPostEdit', '/blueprints/sections/', array('field' => &$field, 'data' => &$data));
                             }
                         }
                     }
                 }
                 if (!$edit) {
                     /**
                      * After the Section has been created, and all the Field's have been
                      * created for this section, but just before the redirect
                      *
                      * @delegate SectionPostCreate
                      * @since Symphony 2.2
                      * @param string $context
                      * '/blueprints/sections/'
                      * @param integer $section_id
                      *  The newly created Section ID.
                      */
                     Symphony::ExtensionManager()->notifyMembers('SectionPostCreate', '/blueprints/sections/', array('section_id' => $section_id));
                     redirect(SYMPHONY_URL . "/blueprints/sections/edit/{$section_id}/created/");
                 } else {
                     /**
                      * After the Section has been updated, and all the Field's have been
                      * updated for this section, but just before the redirect
                      *
                      * @delegate SectionPostEdit
                      * @since Symphony 2.2
                      * @param string $context
                      * '/blueprints/sections/'
                      * @param integer $section_id
                      *  The edited Section ID.
                      */
                     Symphony::ExtensionManager()->notifyMembers('SectionPostEdit', '/blueprints/sections/', array('section_id' => $section_id));
                     redirect(SYMPHONY_URL . "/blueprints/sections/edit/{$section_id}/saved/");
                 }
             }
         }
     }
     if (@array_key_exists("delete", $_POST['action'])) {
         $section_id = array($this->_context[1]);
         /**
          * Just prior to calling the Section Manager's delete function
          *
          * @delegate SectionPreDelete
          * @since Symphony 2.2
          * @param string $context
          * '/blueprints/sections/'
          * @param array $section_ids
          *  An array of Section ID's passed by reference
          */
         Symphony::ExtensionManager()->notifyMembers('SectionPreDelete', '/blueprints/sections/', array('section_ids' => &$section_id));
         foreach ($section_id as $section) {
             SectionManager::delete($section);
         }
         redirect(SYMPHONY_URL . '/blueprints/sections/');
     }
 }
Example #28
0
 public static function updateNamedSections($szRootElement, $oParent, $aSectionArray)
 {
     // Store the current sections
     self::$_current_section_evaluations = $aSectionArray;
     $compiled_result = new XMLElement($szRootElement);
     $oSectionUpdater = new GenericSectionUpdate($oParent);
     $oSectionUpdater->storeRedirect();
     $sm = new SectionManager($oParent);
     $redirect = true;
     foreach ($aSectionArray as $entry) {
         /*
          ** Build an array of field meta-data
          */
         $field_array = array();
         $fields = end($sm->fetch($sm->fetchIDFromHandle($entry)));
         foreach ($fields->fetch() as $field) {
             $tmp = $field->get();
             $field_array[strtolower($tmp['label'])] = $tmp;
         }
         /*
          ** Run the update and return the Symphony XML
          */
         $section_arrays = $oSectionUpdater->updateSections($sm->fetchIDFromHandle($entry), $entry, $field_array);
         foreach ($section_arrays as $section) {
             $compiled_result->appendChild($section);
             if ($section->getAttribute("result") == "error") {
                 $redirect = false;
             }
         }
     }
     // Fix up the SBLs
     $oSectionUpdater->resolveLinks();
     // Do the rollback
     $oSectionUpdater->rollbackTransaction();
     // redirect if set up
     if ($redirect) {
         $oSectionUpdater->actionRedirect();
     }
     return $compiled_result;
 }
 /**
  * Add shortcuts to page DOM
  */
 public function initaliseAdminPageHead($context)
 {
     $page = Administration::instance()->Page;
     // Publish area
     if ($page instanceof ContentPublish and $page->_context['page'] == 'index') {
         $sm = new SectionManager(Administration::instance());
         $section_id = $sm->fetchIDFromHandle($page->_context['section_handle']);
         $shortcuts = $this->__getShortcuts($section_id);
         $page->addElementToHead(new XMLElement('script', "Symphony.Context.add('publish_shortcuts', " . json_encode($shortcuts) . ")", array('type' => 'text/javascript')), 902011);
         $page->addScriptToHead(URL . '/extensions/publish_shortcuts/assets/publish_shortcuts.publish.js', 90211);
     }
     // Preferences
     if ($page instanceof ContentSystemPreferences) {
         $page->addScriptToHead(URL . '/extensions/publish_shortcuts/assets/publish_shortcuts.preferences.js', 90211);
     }
 }
 /**
  * Add publish filter
  */
 public function initaliseAdminPageHead($context)
 {
     $page = Administration::instance()->Page;
     $callback = Administration::instance()->getPageCallback();
     // Include filter?
     if ($page instanceof contentPublish && $callback['context']['page'] == 'index') {
         $sm = new SectionManager(Symphony::Engine());
         $section_handle = $page->_context['section_handle'];
         $section_id = $sm->fetchIDFromHandle($section_handle);
         if (!$section_id) {
             return;
         }
         $section = $sm->fetch($section_id);
         $fields = array();
         // Section is filterable
         //if($section->get('filterable') == 'yes') {
         foreach ($section->fetchFilterableFields() as $field) {
             if (in_array($field->get('type'), $this->_incompatible_publishpanel)) {
                 continue;
             }
             $fields[$field->get('label')]['handle'] = General::sanitize($field->get('element_name'));
             $html = new XMLElement('html');
             /*
             	fields can choose to use getDefaultPublishContent to return a list values only,
             	if their displayPublishPanel HTML is complex
             	https://github.com/nickdunn/publishfiltering/issues/4
             */
             if (method_exists($field, 'getDefaultPublishContent')) {
                 $field->getDefaultPublishContent($html);
             } else {
                 $field->displayPublishPanel($html);
             }
             // filter out some HTML nasties
             $html = preg_replace('/&(?!(#[0-9]+|#x[0-9a-f]+|amp|lt|gt);)/i', '&amp;', $html->generate());
             $dom = new DomDocument();
             libxml_use_internal_errors(true);
             $dom->loadXML($html);
             $xml_errors = libxml_get_errors();
             // XML is malformed, skip this field :-(
             if (!empty($xml_errors)) {
                 continue;
             }
             $xpath = new DomXPath($dom);
             $count = 0;
             foreach ($xpath->query("//*[name()='option'] | //*[name()='li']") as $option) {
                 $value = '';
                 if ($option->getAttribute('value')) {
                     $value = $option->getAttribute('value');
                 } else {
                     $value = $option->nodeValue;
                 }
                 if ($value != '') {
                     $fields[$field->get('label')]['options'][$count]['label'] = $option->nodeValue;
                     $fields[$field->get('label')]['options'][$count]['value'] = $value;
                     $count++;
                 }
             }
             if ($field->get('type') == 'checkbox') {
                 $fields[$field->get('label')]['options'][] = 'Yes';
                 $fields[$field->get('label')]['options'][] = 'No';
             }
         }
         $page->addElementToHead(new XMLElement('script', "Symphony.Context.add('publishfiltering', " . json_encode($fields) . ")", array('type' => 'text/javascript')), 92370001);
         $page->addStylesheetToHead(URL . '/extensions/publishfiltering/assets/publishfiltering.publish.css', 'screen', 92370002);
         $page->addScriptToHead(URL . '/extensions/publishfiltering/assets/publishfiltering.publish.js', 92370003);
         $page->insertDrawer(Widget::Drawer('publish-filtering', __('Filter Entries'), NULL, 'closed', $section_handle), 'horizontal');
         //}
     }
 }