/**
  * The Zend_Feed_EntryAbstract constructor takes the URI of the feed the entry
  * is part of, and optionally an XML construct (usually a
  * SimpleXMLElement, but it can be an XML string or a DOMNode as
  * well) that contains the contents of the entry.
  */
 public function __construct($uri = null, $element = null)
 {
     $this->_uri = $uri;
     if (!$element instanceof DOMElement) {
         if ($element) {
             // Load the feed as an XML DOMDocument object
             @ini_set('track_errors', 1);
             $doc = new DOMDocument();
             $success = @$feedDOMDocument->loadXML($element);
             @ini_restore('track_errors');
             if (!$success) {
                 throw new Zend_Feed_Exception("DOMDocument cannot parse XML: {$php_errormsg}");
             }
             $element = $doc->getElementsByTagName($this->_rootElement)->item(0);
             if (!$element) {
                 throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
             }
         } else {
             $doc = new DOMDocument('1.0', 'utf-8');
             if ($this->_rootNamespace !== null) {
                 $element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
             } else {
                 $element = $doc->createElement($this->_rootElement);
             }
         }
     }
     parent::__construct($element);
 }
Example #2
0
 /**
  * Appends this element to its parent if necessary.
  *
  * @return void
  */
 protected function ensureAppended()
 {
     if (!$this->_appended) {
         $this->_parentElement->getDOM()->appendChild($this->_element);
         $this->_appended = true;
         $this->_parentElement->ensureAppended();
     }
 }
Example #3
0
 /**
  * Map variable access onto the underlying entry representation.
  *
  * Get-style access returns a Zend_Feed_Element representing the
  * child element accessed. To get string values, use method syntax
  * with the __call() overriding.
  *
  * @param  string $var The property to access.
  * @return mixed
  */
 public function __get($var)
 {
     $nodes = $this->_children($var);
     $length = count($nodes);
     if ($length == 1) {
         return new Zend_Feed_Element($nodes[0]);
     } elseif ($length > 1) {
         return array_map(create_function('$e', 'return new Zend_Feed_Element($e);'), $nodes);
     } else {
         // When creating anonymous nodes for __set chaining, don't
         // call appendChild() on them. Instead we pass the current
         // element to them as an extra reference; the child is
         // then responsible for appending itself when it is
         // actually set. This way "if ($foo->bar)" doesn't create
         // a phantom "bar" element in our tree.
         if (strpos($var, ':') !== false) {
             list($ns, $elt) = explode(':', $var, 2);
             $node = $this->_element->ownerDocument->createElementNS(Zend_Feed::lookupNamespace($ns), $elt);
         } else {
             $node = $this->_element->ownerDocument->createElement($var);
         }
         $node = new Zend_Feed_Element($node);
         $node->setParent($this);
         return $node;
     }
 }
Example #4
0
 /**
  * Zend_Feed_Entry_Abstract constructor
  *
  * The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
  * is part of, and optionally an XML construct (usually a
  * SimpleXMLElement, but it can be an XML string or a DOMNode as
  * well) that contains the contents of the entry.
  *
  * @param  string $uri
  * @param  SimpleXMLElement|DOMNode|string  $element
  * @return void
  * @throws Zend_Feed_Exception
  */
 public function __construct($uri = null, $element = null)
 {
     if (!$element instanceof DOMElement) {
         if ($element) {
             // Load the feed as an XML DOMDocument object
             @ini_set('track_errors', 1);
             $doc = new DOMDocument();
             $doc = @Zend_Xml_Security::scan($element, $doc);
             @ini_restore('track_errors');
             if (!$doc) {
                 // prevent the class to generate an undefined variable notice (ZF-2590)
                 if (!isset($php_errormsg)) {
                     if (function_exists('xdebug_is_enabled')) {
                         $php_errormsg = '(error message not available, when XDebug is running)';
                     } else {
                         $php_errormsg = '(error message not available)';
                     }
                 }
                 /**
                  * @see Zend_Feed_Exception
                  */
                 throw new Zend_Feed_Exception("DOMDocument cannot parse XML: {$php_errormsg}");
             }
             $element = $doc->getElementsByTagName($this->_rootElement)->item(0);
             if (!$element) {
                 /**
                  * @see Zend_Feed_Exception
                  */
                 throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
             }
         } else {
             $doc = new DOMDocument('1.0', 'utf-8');
             if ($this->_rootNamespace !== null) {
                 $element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
             } else {
                 $element = $doc->createElement($this->_rootElement);
             }
         }
     }
     parent::__construct($element);
 }
 /**
  * Maps Zotero attachments to Omeka files, et al. 
  * 
  * @param Zend_Feed_Element
  * @param bool Flag indicating that this is a top-level attachment.
  */
 protected function _mapAttachment(Zend_Feed_Element $element, $topLevelAttachment = false)
 {
     if (!$topLevelAttachment) {
         $this->_elementTexts['Zotero']['Attachment Title'][] = array('text' => $element->title(), 'html' => false);
         $urlXpath = '//default:tr[@class="url"]/default:td';
         if ($url = $this->_contentXpath($element->content, $urlXpath, true)) {
             $this->_elementTexts['Zotero']['Attachment URL'][] = array('text' => $url, 'html' => false);
             // If a attachment that is not top-level has no URL, still assign it
             // a placeholder to maintain relationships between the "Attachment
             // Title" and "Attachment Url" elements.
         } else {
             $this->_elementTexts['Zotero']['Attachment URL'][] = array('text' => '[No URL]', 'html' => false);
         }
     }
     // The Zotero API will not return a file unless a private key exists, so
     // prevent unnecessary requests.
     if (!$this->_privateKey) {
         return;
     }
     // Get the file URLs.
     $method = "{$this->_libraryType}ItemFile";
     $urls = $this->_client->{$method}($this->_libraryId, $element->key());
     // Not all attachments have corresponding files in Amazon S3, so return
     // those that do not.
     if (!$urls['s3']) {
         return;
     }
     // Name the file.
     $uri = Zend_Uri::factory($urls['s3']);
     // Set the original filename as the basename of the URL path.
     $name = urldecode(basename($uri->getPath()));
     // Set the file metadata.
     $this->_fileMetadata['files'][] = array('source' => $urls['zotero'], 'name' => $name, 'metadata' => array('Dublin Core' => array('Title' => array(array('text' => $element->title(), 'html' => false)), 'Identifier' => array(array('text' => $url, 'html' => false)))));
 }
Example #6
0
 /**
  * Make accessing individual elements of the feed easier.
  *
  * @param string $var The property to access.
  */
 public function __get($var)
 {
     switch ($var) {
         case 'entry':
             // fall through to the next case
         // fall through to the next case
         case 'entries':
             // fall through to the next case
         // fall through to the next case
         case 'item':
             // fall through to the next case
         // fall through to the next case
         case 'items':
             return $this;
         case 'service.feed':
             // fall through to the next case
         // fall through to the next case
         case 'service.post':
             foreach ($this->_element->childNodes as $child) {
                 if ($child->localName == 'link' && $child->getAttribute('rel') == $var) {
                     return $child->getAttribute('href');
                 }
             }
             return null;
         default:
             return parent::__get($var);
     }
 }