Exemple #1
0
 public static function indexFromXML(DOMElement $xml, $userID)
 {
     if ($xml->textContent === "") {
         error_log("Skipping empty full-text content for item " . $xml->getAttribute('libraryID') . "/" . $xml->getAttribute('key'));
         return;
     }
     $item = Zotero_Items::getByLibraryAndKey($xml->getAttribute('libraryID'), $xml->getAttribute('key'));
     if (!$item) {
         error_log("Item " . $xml->getAttribute('libraryID') . "/" . $xml->getAttribute('key') . " not found during full-text indexing");
         return;
     }
     if (!Zotero_Libraries::userCanEdit($item->libraryID, $userID)) {
         error_log("Skipping full-text content from user {$userID} for uneditable item " . $xml->getAttribute('libraryID') . "/" . $xml->getAttribute('key'));
         return;
     }
     $stats = array();
     foreach (self::$metadata as $prop) {
         $val = $xml->getAttribute($prop);
         $stats[$prop] = $val;
     }
     self::indexItem($item, $xml->textContent, $stats);
 }
 /**
  * @param	SimpleXMLElement	$xml		Data necessary for delete as SimpleXML element
  * @return	void
  */
 public static function deleteFromXML(SimpleXMLElement $xml, $userID)
 {
     $parents = array();
     foreach ($xml->children() as $obj) {
         $libraryID = (int) $obj['libraryID'];
         $key = (string) $obj['key'];
         if ($userID && !Zotero_Libraries::userCanEdit($libraryID, $userID)) {
             throw new Exception("Cannot edit " . self::$objectType . " in library {$libraryID}", Z_ERROR_LIBRARY_ACCESS_DENIED);
         }
         if ($obj->getName() == 'item') {
             $item = Zotero_Items::getByLibraryAndKey($libraryID, $key);
             if (!$item) {
                 continue;
             }
             if (!$item->getSource()) {
                 $parents[] = array('libraryID' => $libraryID, 'key' => $key);
                 continue;
             }
         }
         self::delete($libraryID, $key);
     }
     foreach ($parents as $obj) {
         self::delete($obj['libraryID'], $obj['key']);
     }
 }
 public static function editCheck($obj, $userID = false)
 {
     if (!$userID) {
         return true;
     }
     if (!Zotero_Libraries::userCanEdit($obj->libraryID, $userID, $obj)) {
         throw new Exception("Cannot edit " . static::field('object') . " in library {$obj->libraryID}", Z_ERROR_LIBRARY_ACCESS_DENIED);
     }
 }