Initial note display block (for "pinning" a specific note to a portal page)
authorChuck Hagenbuch <chuck@horde.org>
Sun, 18 Jul 2010 20:17:18 +0000 (16:17 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 18 Jul 2010 21:21:57 +0000 (17:21 -0400)
Anyone up for adding ajax edit capability to it?

mnemo/lib/Block/note.php [new file with mode: 0644]

diff --git a/mnemo/lib/Block/note.php b/mnemo/lib/Block/note.php
new file mode 100644 (file)
index 0000000..4c1ff44
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+
+$block_name = _("View note");
+
+/**
+ * Implementation of Horde_Block api to show a single note.
+ *
+ * @package Horde_Block
+ */
+class Horde_Block_Mnemo_note extends Horde_Block
+{
+    protected $_app = 'mnemo';
+
+    protected function _params()
+    {
+        global $prefs;
+        $memos = Mnemo::listMemos($prefs->getValue('sortby'),
+                                  $prefs->getValue('sortdir'));
+        $notes = array();
+        foreach ($memos as $memo) {
+            $notes[$memo['uid']] = $memo['desc'];
+        }
+
+        return array(
+            'note_uid' => array(
+                'type' => 'enum',
+                'name' => _("Show this note"),
+                'values' => $notes,
+            ),
+            'note_name' => array(
+                'type' => 'hidden',
+            ),
+        );
+    }
+
+    protected function _title()
+    {
+        return htmlspecialchars($this->_getTitle());
+    }
+
+    protected function _content()
+    {
+        $memo = $this->_getNote();
+
+        $html = '<div class="noteBody">';
+        $body = Horde_Text_Filter::filter($memo['body'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'class' => null));
+        try {
+            $body = Horde::callHook('format_description', array($body), 'mnemo', $body);
+        } catch (Horde_Exception_HookNotSet $e) {}
+        $html .= $body . '</div>';
+
+        return $html;
+    }
+
+    private function _getNote()
+    {
+        if (!isset($this->_params['note_uid'])) {
+            throw new Horde_Block_Exception(_("No note loaded"));
+        }
+
+        $uid = $this->_params['note_uid'];
+        $storage = Mnemo_Driver::singleton();
+        $memo = $storage->getByUID($uid);
+        if (is_a($memo, 'PEAR_Error')) {
+            if (!empty($this->_params['note_name'])) {
+                $msg = sprintf(_("An error occurred displaying %s"), $this->_params['note_name']);
+            } else {
+                $msg = _("An error occurred displaying the note");
+            }
+            throw new Horde_Block_Exception($msg);
+        }
+
+        return $memo;
+    }
+
+    private function _getTitle()
+    {
+        if (empty($this->_params['note_name'])) {
+            $note = $this->_getNote();
+            $this->_params['note_name'] = $note['desc'];
+        }
+        return $this->_params['note_name'];
+    }
+}