Get preview text for a note (the first 20 lines or so).
public static getNotePreview ( array $note ) : string | ||
$note | array | The note array |
return | string | A few lines of the note for previews or tooltips. |
/** */ protected function _content() { global $registry, $prefs; if (!empty($this->_params['show_notepad'])) { $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create(); } $html = ''; $memos = Mnemo::listMemos($prefs->getValue('sortby'), $prefs->getValue('sortdir')); foreach ($memos as $id => $memo) { $html .= '<tr>'; if (!empty($this->_params['show_actions'])) { $editImg = Horde_Themes::img('edit.png'); $editurl = Horde::url('memo.php')->add(array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'])); $html .= '<td width="1%">' . Horde::link(htmlspecialchars(Horde::url($editurl, true)->add('actionID', 'modify_memo')), _("Edit Note")) . Horde::img($editImg, _("Edit Note")) . '</a></td>'; } if (!empty($this->_params['show_notepad'])) { $html .= '<td>' . htmlspecialchars(Mnemo::getLabel($shares->getShare($memo['memolist_id']))) . '</td>'; } $viewurl = Horde::url('view.php')->add(array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'])); $html .= '<td>' . Horde::linkTooltip(htmlspecialchars(Horde::url($viewurl, true)), '', '', '', '', $memo['body'] != $memo['desc'] ? Mnemo::getNotePreview($memo) : '') . (strlen($memo['desc']) ? htmlspecialchars($memo['desc']) : '<em>' . _("Empty Note") . '</em>') . '</a> <ul class="horde-tags">'; foreach ($memo['tags'] as $tag) { $html .= '<li>' . htmlspecialchars($tag) . '</li>'; } $html .= '</ul></td></tr>'; } if (!$memos) { return '<p><em>' . _("No notes to display") . '</em></p>'; } return '<table cellspacing="0" width="100%" class="linedRow">' . $html . '</table>'; }
$view->headers[] = array('id' => 's' . MNEMO::SORT_MOD_DATE, 'sorted' => $sortby == Mnemo::SORT_MOD_DATE, 'width' => '2%', 'label' => Horde::widget(array('url' => $baseurl->add('sortby', MNEMO::SORT_MOD_DATE), 'class' => 'sortlink', 'title' => _("Date")))); foreach ($memos as $memo_id => &$memo) { try { $share = $mnemo_shares->getShare($memo['memolist_id']); } catch (Horde_Share_Exception $e) { $notification->push($e); continue; } if ($view->showNotepad) { $memo['notepad'] = Mnemo::getLabel($share); } if ($share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $label = sprintf(_("Edit \"%s\""), $memo['desc']); $memo['edit'] = Horde::url('memo.php')->add(array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'], 'actionID' => 'modify_memo'))->link(array('title' => $label)) . Horde::img('edit.png', $label, '') . '</a>'; } $memo['link'] = Horde::linkTooltip(Horde::url('view.php')->add(array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'])), '', '', '', '', $memo['body'] != $memo['desc'] ? Mnemo::getNotePreview($memo) : '') . (strlen($memo['desc']) ? htmlspecialchars($memo['desc']) : '<em>' . _("Empty Note") . '</em>') . '</a>'; // Get memo's most recent modification date or, if nonexistent, // the creation (add) date if (isset($memo['modified'])) { $modified = $memo['modified']; } elseif (isset($memo['created'])) { $modified = $memo['created']; } else { $modified = null; } if ($modified) { $memo['modifiedStamp'] = $modified->timestamp(); $memo['modifiedString'] = $modified->strftime($prefs->getValue('date_format')); } else { $memo['modifiedStamp'] = $memo['modifiedString'] = ''; }
/** * Renders the view. * * @param Horde_PageOutput $output The output object. * * @return string The HTML needed to render the view. */ public function render(Horde_PageOutput $output) { global $prefs, $injector, $registry, $mnemo_shares; $output->addScriptFile('tables.js', 'horde'); $output->addScriptFile('quickfinder.js', 'horde'); $output->addScriptFile('list.js'); $output->header(array('title' => $this->_title)); $view = $injector->createInstance('Horde_View'); $view->count = count($this->_notes); $view->searchImg = Horde::img('search.png', _("Search"), ''); $view->searchUrl = Horde::url('search.php'); $view->title = $this->_title; $view->browser = $this->_showTagBrowser ? $this->_getRelatedTags() . $this->_getTagTrail() : ''; if (count($this->_notes)) { $sortby = $prefs->getValue('sortby'); $sortdir = $prefs->getValue('sortdir'); $output->addInlineJsVars(array('Mnemo_List.ajaxUrl' => $registry->getServiceLink('ajax', 'mnemo')->url . 'setPrefValue')); $view->editImg = Horde::img('edit.png', _("Edit Note"), ''); $view->showNotepad = $prefs->getValue('show_notepad'); $view->sortdirclass = $sortdir ? 'sortup' : 'sortdown'; $view->headers = array(); if ($view->showNotepad) { $view->headers[] = array('id' => 's' . Mnemo::SORT_NOTEPAD, 'sorted' => $sortby == Mnemo::SORT_NOTEPAD, 'width' => '2%', 'label' => Horde::widget(array('url' => $this->_baseurl->add('sortby', Mnemo::SORT_NOTEPAD), 'class' => 'sortlink', 'title' => _("Notepad")))); } $view->headers[] = array('id' => 's' . MNEMO::SORT_DESC, 'sorted' => $sortby == MNEMO::SORT_DESC, 'width' => '80%', 'label' => Horde::widget(array('url' => $this->_baseurl->add('sortby', Mnemo::SORT_DESC), 'class' => 'sortlink', 'title' => _("No_te")))); $view->headers[] = array('id' => 's' . MNEMO::SORT_MOD_DATE, 'sorted' => $sortby == Mnemo::SORT_MOD_DATE, 'width' => '2%', 'label' => Horde::widget(array('url' => $this->_baseurl->add('sortby', MNEMO::SORT_MOD_DATE), 'class' => 'sortlink', 'title' => _("Date")))); foreach ($this->_notes as $memo_id => &$memo) { try { $share = $mnemo_shares->getShare($memo['memolist_id']); } catch (Horde_Share_Exception $e) { $notification->push($e); continue; } if ($view->showNotepad) { $memo['notepad'] = Mnemo::getLabel($share); } if ($share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $label = sprintf(_("Edit \"%s\""), $memo['desc']); $memo['edit'] = Horde::url('memo.php')->add(array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'], 'actionID' => 'modify_memo'))->link(array('title' => $label)) . Horde::img('edit.png', $label, '') . '</a>'; } $memo['link'] = Horde::linkTooltip(Horde::url('view.php')->add(array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'])), '', '', '', '', $memo['body'] != $memo['desc'] ? Mnemo::getNotePreview($memo) : '') . (strlen($memo['desc']) ? htmlspecialchars($memo['desc']) : '<em>' . _("Empty Note") . '</em>') . '</a>'; // Get memo's most recent modification date or, if nonexistent, // the creation (add) date if (isset($memo['modified'])) { $modified = $memo['modified']; } elseif (isset($memo['created'])) { $modified = $memo['created']; } else { $modified = null; } if ($modified) { $memo['modifiedStamp'] = $modified->timestamp(); $memo['modifiedString'] = $modified->strftime($prefs->getValue('date_format')); } else { $memo['modifiedStamp'] = $memo['modifiedString'] = ''; } } } Horde::startBuffer(); echo $view->render('list/header'); if (count($this->_notes)) { echo $view->render('list/memo_headers'); echo $view->renderPartial('list/summary', array('collection' => array_values($this->_notes))); echo $view->render('list/memo_footers'); } else { echo $view->render('list/empty'); } $output->footer(); return Horde::endBuffer(); }