function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL)
 {
     if (!isset(Administration::instance()->Page)) {
         return;
     }
     // work out what page we are on, get portions of the URL
     $callback = Administration::instance()->getPageCallback();
     $entry_id = $callback['context']['entry_id'];
     // get an Entry object for this entry
     $entries = EntryManager::fetch($entry_id);
     if (is_array($entries)) {
         $entry = reset($entries);
     }
     // parse dynamic portions of the panel URL
     $url = $this->parseExpression($entry, $this->get('url_expression'));
     if (!preg_match('/^http/', $url)) {
         $url = URL . $url;
     }
     // create Symphony cookie to pass with each request
     $cookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
     session_write_close();
     $gateway = new Gateway();
     $gateway->init($url);
     $gateway->setopt('TIMEOUT', 10);
     $gateway->setopt(CURLOPT_COOKIE, $cookie);
     $gateway->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
     $result = $gateway->exec();
     // a unique name for this panel instance
     $instance_id = $callback['context']['section_handle'] . '_' . $this->get('element_name');
     $container = new XMLELement('div', $result);
     $container->setAttribute('id', $instance_id);
     $container->setAttribute('class', 'inline frame');
     $label = new XMLElement('label', $this->get('label'));
     $label->appendChild($container);
     $wrapper->appendChild($label);
     $asset_index = $this->get('id') * rand(10, 100);
     // add panel-specific styling
     $instance_css = '/html-panel/' . $instance_id . '.css';
     if (file_exists(WORKSPACE . $instance_css)) {
         Administration::instance()->Page->addStylesheetToHead(URL . '/workspace' . $instance_css, 'screen', $asset_index++);
     }
     // add panel-specific behaviour
     $instance_js = '/html-panel/' . $instance_id . '.js';
     if (file_exists(WORKSPACE . $instance_js)) {
         Administration::instance()->Page->addScriptToHead(URL . '/workspace' . $instance_js, $asset_index++);
     }
 }
Ejemplo n.º 2
0
 public function appendElement($context)
 {
     // if in edit or new page
     if ($this->isInEditOrNew()) {
         // Get this section's limit
         $limits = $this->getSectionLimit();
         // Exit early if no limits where found
         if ($limits === FALSE || empty($limits) || !is_array($limits)) {
             return;
         }
         // Exit early if the limit is one
         if ($limits['limit'] == 1) {
             return;
         }
         // add new if limit is 0 or total is less than limit
         $shouldAddNew = $limits['limit'] == 0 || $limits['total'] + 1 < $limits['limit'];
         // add return if the limit is not 1
         $shouldAddReturn = $limits['limit'] != 1;
         $page = $context['oPage'];
         $form = $page->Form;
         $button_wrap = new XMLELement('div', NULL, array('id' => 'save-and', 'style' => 'float:right'));
         if ($shouldAddReturn) {
             // add return button in wrapper
             $button_return = $this->createButton('save-and-return', 'Save & return');
             $hidden_return = $this->createHidden('save-and-return-h');
             $button_wrap->appendChild($button_return);
             $button_wrap->appendChild($hidden_return);
         }
         if ($shouldAddNew) {
             // add the new button
             $button_new = $this->createButton('save-and-new', 'Save & new');
             $hidden_new = $this->createHidden('save-and-new-h');
             $button_wrap->appendChild($button_new);
             $button_wrap->appendChild($hidden_new);
         }
         // save current query string: the raw (visible) query string
         $queryString = explode('?', $_SERVER['REQUEST_URI'], 2);
         if ($queryString != FALSE && count($queryString) == 2) {
             $queryString = $queryString[1];
         } else {
             $queryString = '';
         }
         $qs_hidden = $this->createHidden('save-and-qs');
         $qs_hidden->setAttribute('value', $queryString);
         $button_wrap->appendChild($qs_hidden);
         // add content to the right div
         $div_action = $this->getChildrenWithClass($form, 'div', 'actions');
         // if there is no fields, div_action may not be there
         if ($div_action != NULL) {
             $div_action->appendChild($button_wrap);
         }
     }
 }
 /**
  * Group associated entries by id
  *
  * @param XMLELement $associated_xml
  *  The Data Source output
  * @return array
  */
 private function groupAssociatedEntries($associated_xml)
 {
     $associated_items = array();
     foreach ($associated_xml->getChildren() as $entry) {
         if ($entry->getName() === 'entry') {
             $associated_items[$entry->getAttribute('id')] = $entry->getChildren();
         }
     }
     return $associated_items;
 }