Exemplo n.º 1
0
 public function appendFormattedElement(XMLElement $wrapper, StdClass $settings, StdClass $data, $entry_id = null)
 {
     $wrapper->setAttribute('id', $data->{'id'});
     $title = new XMLElement('title');
     $title->setValue(General::sanitize($data->{'title'}));
     $title->setAttribute('handle', Lang::createHandle($data->{'title'}));
     $wrapper->appendChild($title);
     $wrapper->appendChild(new XMLElement('url', General::sanitize($data->{'url'})));
     $wrapper->appendChild(new XMLElement('thumbnail', General::sanitize($data->{'thumb'})));
     $wrapper->appendChild(new XMLElement('driver', General::sanitize($data->{'driver'})));
     // Enable better error handling:
     libxml_use_internal_errors(true);
     $driver = ServiceDispatcher::getServiceDriver($data->{'url'});
     $xml = new DOMDocument();
     $xml->loadXML($data->{'xml'});
     // Ignore any errors:
     libxml_clear_errors();
     // Find the root element:
     $root = $xml->getElementsByTagName($driver->getRootTagName())->item(0);
     // Data was found:
     if ($root instanceof DOMNode) {
         $oembed = new XMLElement('oembed');
         foreach ($root->childNodes as $node) {
             $element = new XMLElement($node->tagName);
             $element->setValue(General::sanitize($node->textContent));
             $oembed->appendChild($element);
         }
         $wrapper->appendChild($oembed);
     } else {
         $error = new XMLElement('error');
         $error->setValue(__('Error while loading the xml into the document'));
         $wrapper->appendChild($error);
     }
 }
Exemplo n.º 2
0
 /**
  *
  * Builds the UI for the publish page
  * @param XMLElement $wrapper
  * @param mixed $data
  * @param mixed $flagWithError
  * @param string $fieldnamePrefix
  * @param string $fieldnamePostfix
  */
 public function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL)
 {
     // add stylesheet
     if (Symphony::Engine() instanceof Administration) {
         Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/oembed_field/assets/publish.oembed.css', 'screen', 104, false);
     }
     $isRequired = $this->get('required') == 'yes';
     $isUnique = $this->get('unique') == 'yes';
     $isUniqueMedia = $this->get('unique_media') == 'yes';
     $value = General::sanitize($data['url']);
     $label = Widget::Label($this->get('label'));
     // not required and unique label
     if (!$isRequired && $isUniqueMedia) {
         $label->appendChild(new XMLElement('i', __('Optional') . ', ' . __('Unique')));
         // not required label
     } else {
         if (!$isRequired) {
             $label->appendChild(new XMLElement('i', __('Optional')));
             // unique label
         } else {
             if ($isUniqueMedia) {
                 $label->appendChild(new XMLElement('i', __('Unique')));
             }
         }
     }
     // input form
     $url = new XMLElement('input');
     $url->setAttribute('type', 'text');
     $url->setAttribute('name', 'fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix);
     $url->setAttribute('value', $value);
     $drivers = new XMLElement('div', __('<i class="supported">Supported services: %s</i>', array(str_replace(',', ', ', $this->get('driver')))));
     if (strlen($value) == 0 || $flagWithError != NULL) {
         // do nothing
     } else {
         // hides input and drivers
         $url->setAttribute('class', 'irrelevant');
         $drivers->setAttribute('class', 'irrelevant');
         // create a resource container
         $res_container = new XMLElement('span');
         $res_container->setAttribute('class', 'frame');
         $change = new XMLElement('a', __('Change'));
         $change->setAttribute('class', 'change');
         $or = new XMLElement('span', __(' or '));
         $remove = new XMLElement('a', __('Remove'));
         $remove->setAttribute('class', 'change remove');
         $e_options = array('location' => $this->get('location'), 'width' => '640', 'height' => '360', 'width_side' => '320', 'height_side' => '160');
         // get the embed code
         $driver = ServiceDispatcher::getServiceDriver($value);
         $embed = null;
         if (!$driver) {
             $embed = __('Error. Service unknown.');
         } else {
             $embed = $driver->getEmbedCode($data, $e_options);
         }
         $res_container->setValue("<div>{$embed}</div>");
         $res_container->appendChild($change);
         $res_container->appendChild($or);
         $res_container->appendChild($remove);
         $label->appendChild($res_container);
     }
     // append the input tag into the label
     $label->appendChild($url);
     // append the allowed drivers list
     $label->appendChild($drivers);
     // error management
     if ($flagWithError != NULL) {
         $wrapper->appendChild(self::Error($label, $flagWithError));
     } else {
         $wrapper->appendChild($label);
     }
 }