/** * * @param array $row Hash of the note data, db keys. * @param string $passphrase The encryption passphrase. * * @return array a Task hash. * @throws Mnemo_Exception */ protected function _buildNote($row, $passphrase = null) { // Make sure notes always have a UID. if (empty($row['memo_uid'])) { $row['memo_uid'] = strval(new Horde_Support_Guid()); $query = 'UPDATE ' . $this->_table . ' SET memo_uid = ?' . ' WHERE memo_owner = ? AND memo_id = ?'; $values = array($row['memo_uid'], $row['memo_owner'], $row['memo_id']); try { $this->_db->update($query, $values); } catch (Horde_Db_Exception $e) { throw new Mnemo_Exception($e->getMessage()); } } // Decrypt note if requested. $encrypted = false; $body = $this->_column->binaryToString($row['memo_body']); $body = Horde_String::convertCharset($body, $this->_charset, 'UTF-8'); if (strpos($body, '-----BEGIN PGP MESSAGE-----') === 0) { $encrypted = true; if (empty($passphrase)) { $passphrase = Mnemo::getPassphrase($row['memo_id']); } if (empty($passphrase)) { $body = new Mnemo_Exception(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE); } else { try { $body = $this->_decrypt($body, $passphrase); $body = $body->message; } catch (Mnemo_Exception $e) { $body = $e; } Mnemo::storePassphrase($row['memo_id'], $passphrase); } } // Create a new note based on $row's values. $uid = Horde_String::convertCharset($row['memo_uid'], $this->_charset, 'UTF-8'); $memo = array('memolist_id' => $row['memo_owner'], 'memo_id' => $row['memo_id'], 'uid' => $uid, 'desc' => Horde_String::convertCharset($row['memo_desc'], $this->_charset, 'UTF-8'), 'body' => $body, 'tags' => $GLOBALS['injector']->getInstance('Mnemo_Tagger')->getTags($uid, 'note'), 'encrypted' => $encrypted); try { $userId = $GLOBALS['registry']->getAuth(); $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory('mnemo:' . $row['memo_owner'] . ':' . $row['memo_uid']); foreach ($log as $entry) { switch ($entry['action']) { case 'add': $memo['created'] = new Horde_Date($entry['ts']); if ($userId != $entry['who']) { $memo['createdby'] = sprintf(_("by %s"), Mnemo::getUserName($entry['who'])); } else { $memo['createdby'] = _("by me"); } break; case 'modify': $memo['modified'] = new Horde_Date($entry['ts']); if ($userId != $entry['who']) { $memo['modifiedby'] = sprintf(_("by %s"), Mnemo::getUserName($entry['who'])); } else { $memo['modifiedby'] = _("by me"); } break; } } } catch (Horde_Exception $e) { } return $memo; }
/** * Modifies an existing note. * * @param string $noteId The note to modify. * @param string $desc The first line of the note. * @param string $body The whole note body. * @param string $tags The tags of the note. * @param string $passphrase The passphrase to encrypt the note with. * * @throws Mnemo_Exception */ public function modify($noteId, $desc, $body, $tags = '', $passphrase = null) { if ($passphrase) { $body = $this->_encrypt($body, $passphrase); Mnemo::storePassphrase($noteId, $passphrase); } $uid = $this->_modify($noteId, $desc, $body, $tags); // Update tags. $GLOBALS['injector']->getInstance('Mnemo_Tagger')->replaceTags($uid, $tags, $GLOBALS['registry']->getAuth(), 'note'); // Log the modification of this item in the history log. if ($uid) { try { $GLOBALS['injector']->getInstance('Horde_History')->log('mnemo:' . $this->_notepad . ':' . $uid, array('action' => 'modify'), true); } catch (Horde_Exception $e) { } } }
/** * Build a note based on data array * * @param array $note The data for the note * @param string $passphrase A passphrase for decrypting a note * * @return array The converted data array representing the note */ protected function _buildNote($note, $passphrase = null) { $encrypted = false; $body = $note['body']; $id = Horde_Url::uriB64Encode($note['uid']); if (strpos($body, '-----BEGIN PGP MESSAGE-----') === 0) { $encrypted = true; if (empty($passphrase)) { $passphrase = Mnemo::getPassphrase($id); } if (empty($passphrase)) { $body = new Mnemo_Exception(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE); } else { try { $body = $this->_decrypt($body, $passphrase)->message; } catch (Mnemo_Exception $e) { $body = $e; } Mnemo::storePassphrase($id, $passphrase); } } $tagger = $GLOBALS['injector']->getInstance('Mnemo_Tagger'); $tags = $tagger->getTags($note['uid'], 'note'); if (!empty($note['categories'])) { usort($tags, 'strcoll'); if (array_diff($note['categories'], $tags)) { $tagger->replaceTags($note['uid'], $note['categories'], $GLOBALS['registry']->getAuth(), 'note'); } $tags = $note['categories']; } $result = array('memolist_id' => $this->_notepad, 'memo_id' => $id, 'uid' => $note['uid'], 'tags' => $tags, 'desc' => $note['summary'], 'encrypted' => $encrypted, 'body' => $body); if (!empty($note['creation-date'])) { $result['created'] = new Horde_Date($note['creation-date']); } if (!empty($note['last-modification-date'])) { $result['modified'] = new Horde_Date($note['last-modification-date']); } return $result; }