Beispiel #1
0
	/**
	* Get the text of an item note
	**/
	public function getNote($sanitized=false, $htmlspecialchars=false) {
		if (!$this->isNote() && !$this->isAttachment()) {
			throw new Exception("getNote() can only be called on notes and attachments");
		}
		
		if (!$this->id) {
			return '';
		}
		
		// Store access time for later garbage collection
		//$this->noteAccessTime = new Date();
		
		if ($sanitized) {
			if ($htmlspecialchars) {
				throw new Exception('$sanitized and $htmlspecialchars cannot currently be used together');
			}
			
			if (is_null($this->noteText)) {
				$sql = "SELECT note, noteSanitized FROM itemNotes WHERE itemID=?";
				$row = Zotero_DB::rowQuery($sql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
				if (!$row) {
					$row = array('note' => '', 'noteSanitized' => '');
				}
				$this->noteText = $row['note'];
				$this->noteTextSanitized = $row['noteSanitized'];
			}
			// Empty string means the original note is sanitized
			return $this->noteTextSanitized === '' ? $this->noteText : $this->noteTextSanitized;
		}
		
		if (is_null($this->noteText)) {
			$note = Zotero_Notes::getCachedNote($this->libraryID, $this->id);
			if ($note === false) {
				$sql = "SELECT note FROM itemNotes WHERE itemID=?";
				$note = Zotero_DB::valueQuery($sql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
			}
			$this->noteText = $note !== false ? $note : '';
		}
		
		if ($this->noteText !== '' && $htmlspecialchars) {
			$noteHash = $this->getNoteHash();
			if ($noteHash) {
				$cacheKey = "htmlspecialcharsNote_$noteHash";
				$note = Z_Core::$MC->get($cacheKey);
				if ($note === false) {
					$note = htmlspecialchars($this->noteText);
					Z_Core::$MC->set($cacheKey, $note);
				}
			}
			else {
				error_log("WARNING: Note hash is empty");
				$note = htmlspecialchars($this->noteText);
			}
			return $note;
		}
		
		return $this->noteText;
	}
Beispiel #2
0
 /**
  * Get the text of an item note
  **/
 public function getNote($sanitized = false, $htmlspecialchars = false)
 {
     if (!$this->isNote() && !$this->isAttachment()) {
         throw new Exception("getNote() can only be called on notes and attachments");
     }
     if (!$this->id) {
         return '';
     }
     // Store access time for later garbage collection
     //$this->noteAccessTime = new Date();
     if ($sanitized) {
         if ($htmlspecialchars) {
             throw new Exception('$sanitized and $htmlspecialchars cannot currently be used together');
         }
         if (is_null($this->noteText)) {
             $sql = "SELECT note, noteSanitized FROM itemNotes WHERE itemID=?";
             $row = Zotero_DB::rowQuery($sql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
             if (!$row) {
                 $row = array('note' => '', 'noteSanitized' => '');
             }
             // Empty string means the note is sanitized
             // Null means not yet processed
             if ($row['noteSanitized'] === '') {
                 $this->noteText = $row['note'];
                 $this->noteTextSanitized =& $this->noteText;
             } else {
                 $this->noteText = $row['note'];
                 if (!is_null($row['noteSanitized'])) {
                     $this->noteTextSanitized = $row['noteSanitized'];
                 }
             }
         }
         // DEBUG: Shouldn't be necessary anymore
         if (is_null($this->noteTextSanitized)) {
             $sanitized = Zotero_Notes::sanitize($this->noteText);
             // If sanitized version is the same, use reference
             if ($this->noteText == $sanitized) {
                 $this->noteTextSanitized =& $this->noteText;
             } else {
                 $this->noteTextSanitized = $sanitized;
             }
         }
         return $this->noteTextSanitized;
     }
     if (is_null($this->noteText)) {
         $note = Zotero_Notes::getCachedNote($this->libraryID, $this->id);
         if ($note === false) {
             $sql = "SELECT note FROM itemNotes WHERE itemID=?";
             $note = Zotero_DB::valueQuery($sql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
         }
         $this->noteText = $note ? $note : '';
     }
     if ($this->noteText !== '' && $htmlspecialchars) {
         $noteHash = $this->getNoteHash();
         if (!$noteHash) {
             throw new Exception("Note hash is empty");
         }
         $cacheKey = "htmlspecialcharsNote_{$noteHash}";
         $note = Z_Core::$MC->get($cacheKey);
         if ($note === false) {
             $note = htmlspecialchars($this->noteText);
             Z_Core::$MC->set($cacheKey, $note);
         }
         return $note;
     }
     return $this->noteText;
 }