/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInfo() { $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); if (!$this->getConfigParam('zip')) { $this->setConfigParam('zip', Horde_Compress::factory('Zip')); } $zipInfo = $this->getConfigParam('zip')->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST)); $fileCount = count($zipInfo); $name = $this->_mimepart->getName(true); if (empty($name)) { $name = Horde_Mime_Viewer_Translation::t("unnamed"); } $monospace = $this->getConfigParam('monospace'); $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name . "\n" . Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . " bytes\n" . sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . "\n\n" . str_repeat(' ', 15) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT) . "\n", 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . str_repeat('-', 74) . "\n"; foreach ($zipInfo as $key => $val) { $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']); $val['name'] = Horde_String::pad(Horde_String::truncate($val['name'], 15), 15, ' ', STR_PAD_RIGHT); $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT); $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT); $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT); $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT); $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT); reset($val); while (list($k, $v) = each($val)) { $val[$k] = $this->_textFilter($v, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)); } if (!is_null($this->_callback)) { $val = call_user_func($this->_callback, $key, $val); } $text .= $val['name'] . $val['attr'] . $val['size'] . $val['date'] . $val['method'] . $val['ratio'] . "\n"; } return $this->_renderReturn(nl2br($text . str_repeat('-', 74) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset); }
/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInfo() { $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); if (!$this->getConfigParam('rar')) { $this->setConfigParam('rar', Horde_Compress::factory('rar')); } $rarData = $this->getConfigParam('rar')->decompress($contents); $fileCount = count($rarData); $name = $this->_mimepart->getName(true); if (empty($name)) { $name = Horde_Mime_Viewer_Translation::t("unnamed"); } $monospace = $this->getConfigParam('monospace'); $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name, 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(Horde_String::pad(Horde_Mime_Viewer_Translation::t("File Name"), 50, ' ', STR_PAD_RIGHT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 109) . "\n"; foreach ($rarData as $val) { $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']); $text .= $this->_textFilter(Horde_String::pad($val['name'], 50, ' ', STR_PAD_RIGHT) . Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) . Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT), 'space2html', array('encode' => true, 'encode_all' => true)) . "\n"; } return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset); }
public function deflist($block) { $elements = explode($this->wiki->delim, $block); $term = false; $list = array(); foreach ($elements as $element) { if ($term === false) { $term = $element; } else { $list[$term] = $element; $term = false; } } $term_length = max(array_map('strlen', array_keys($list))); $result = ''; foreach ($list as $term => $info) { $lead = Horde_String::pad($term . ': ', $term_length + 2); $definition = Horde_String::wordwrap($lead . $info, max(80, $term_length + 30), "\n" . str_repeat(' ', $term_length + 3)); $result .= ':' . $definition . "\n"; } $result .= "\n"; return $result; }
/** * Run the module. * * @param Horde_Cli $cli The CLI handler. * @param mixed $options An array of options. * @param mixed $arguments An array of arguments. * @param array &$world A list of initialized dependencies. * * @return NULL */ public function run($cli, $options, $arguments, &$world) { if (!isset($arguments[1])) { $action = 'folders'; } else { $action = $arguments[1]; } switch ($action) { case 'folders': $folders = $world['storage']->getList()->listFolders(); foreach ($folders as $folder) { $cli->writeln($folder); } break; case 'types': $types = $world['storage']->getList()->getQuery()->listTypes(); if (!empty($types)) { $pad = max(array_map('strlen', array_keys($types))) + 2; foreach ($types as $folder => $type) { $cli->writeln(Horde_String::pad($folder . ':', $pad) . $type); } } break; case 'type': if (!isset($arguments[2])) { throw new Horde_Kolab_Cli_Exception('You must provide a TYPE argument!'); } $type = $arguments[2]; $folders = $world['storage']->getList()->getQuery()->listByType($type); foreach ($folders as $folder) { $cli->writeln($folder); } break; case 'owners': $owners = $world['storage']->getList()->getQuery()->listOwners(); if (!empty($owners)) { $pad = max(array_map('strlen', array_keys($owners))) + 2; foreach ($owners as $folder => $owner) { $cli->writeln(Horde_String::pad($folder . ':', $pad) . $owner); } } break; case 'defaults': $defaults = $world['storage']->getList()->getQuery()->listDefaults(); if (!empty($defaults)) { foreach ($defaults as $owner => $folders) { $cli->writeln('User "' . $owner . '":'); $cli->writeln(); foreach ($folders as $type => $folder) { $cli->writeln(' ' . Horde_String::pad($type . ':', 14) . $folder); } $cli->writeln(); } } break; case 'aclsupport': if ($world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->hasAclSupport()) { echo "The remote server supports ACL.\n"; } else { echo "The remote server does not support ACL.\n"; } break; case 'namespaces': $cli->writeln((string) $world['storage']->getList()->getNamespace()); break; case 'sync': $folders = $world['storage']->getList()->synchronize(); break; default: $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error'); break; } }
/** * Wrap up the listing. This will produce a condensed list of packages in * case quiet Output was requested. * * @return NULL */ private function _finish() { if (empty($this->_short_list)) { return; } $channels = array(); $names = array(); $colors = array(); foreach ($this->_short_list as $key => $element) { $channels[] = $element['channel']; $names[] = $element['name']; $colors[] = $element['color']; } array_multisort($channels, $names, $colors); foreach ($names as $key => $name) { $this->_output->{$colors[$key]}(Horde_String::pad($name, 28) . Horde_String::pad('[' . $channels[$key] . ']', 20)); } }
/** * Return nicely formatted text representing the headers to display with * in-line forwarded messages. * * @return string */ public function getForwardHeaders() { $tmp = array(); $h = $this->getHeaders(); if ($ob = $h->getValue('date')) { $tmp[Horde_ActiveSync_Translation::t('Date')] = $ob; } if ($ob = strval($h->getOb('from'))) { $tmp[Horde_ActiveSync_Translation::t('From')] = $ob; } if ($ob = strval($h->getOb('reply-to'))) { $tmp[Horde_ActiveSync_Translation::t('Reply-To')] = $ob; } if ($ob = $h->getValue('subject')) { $tmp[Horde_ActiveSync_Translation::t('Subject')] = $ob; } if ($ob = strval($h->getOb('to'))) { $tmp[Horde_ActiveSync_Translation::t('To')] = $ob; } if ($ob = strval($h->getOb('cc'))) { $tmp[Horde_ActiveSync_Translation::t('Cc')] = $ob; } $max = max(array_map(array('Horde_String', 'length'), array_keys($tmp))) + 2; $text = ''; foreach ($tmp as $key => $val) { $text .= Horde_String::pad($key . ': ', $max, ' ', STR_PAD_LEFT) . $val . "\n"; } return $text; }
/** * Returns a plain text representation of a ticket. */ public function toString() { $fields = array('queue' => _("Queue"), 'version' => _("Version"), 'type' => _("Type"), 'state' => _("State"), 'priority' => _("Priority"), 'due' => _("Due")); /* Find longest translated field name. */ $length = 0; foreach (array_merge($fields, array(_("Summary"), _("Owners"))) as $field) { $length = max($length, Horde_String::length($field)); } $wrap_break = "\n" . str_repeat(' ', $length + 2) . '| '; $wrap_width = 73 - $length; /* Ticket properties. */ $message = ' ' . Horde_String::pad(_("Ticket"), $length) . ' | ' . $this->_id . "\n" . ' ' . Horde_String::pad(_("Summary"), $length) . ' | ' . Horde_String::wrap($this->get('summary'), $wrap_width, $wrap_break) . "\n"; foreach ($fields as $field => $label) { if ($name = $this->get($field . '_name')) { $message .= ' ' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($name, $wrap_width, $wrap_break) . "\n"; } } $message .= ' ' . Horde_String::pad(_("Owners"), $length) . ' | ' . Horde_String::wrap(Whups::getOwners($this->_id, false, true), $wrap_width, $wrap_break) . "\n"; return $message; }
/** * Determine the header information to display in the forward/reply. * * @param Horde_Mime_Headers $h The headers object for the message. * * @return string The header information for the original message. */ protected function _getMsgHeaders($h) { $tmp = array(); if ($ob = $h['date']) { $tmp[_("Date")] = $ob->value; } if ($ob = strval($h['from'])) { $tmp[_("From")] = $ob; } if ($ob = strval($h['reply-to'])) { $tmp[_("Reply-To")] = $ob; } if ($ob = $h['subject']) { $tmp[_("Subject")] = $ob->value; } if ($ob = strval($h['to'])) { $tmp[_("To")] = $ob; } if ($ob = strval($h['cc'])) { $tmp[_("Cc")] = $ob; } $text = ''; if (!empty($tmp)) { $max = max(array_map(array('Horde_String', 'length'), array_keys($tmp))) + 2; foreach ($tmp as $key => $val) { $text .= Horde_String::pad($key . ': ', $max, ' ', STR_PAD_LEFT) . $val . "\n"; } } return $text; }
/** * Run the module. * * @param Horde_Cli $cli The CLI handler. * @param mixed $options An array of options. * @param mixed $arguments An array of arguments. * @param array &$world A list of initialized dependencies. * * @return NULL */ public function run($cli, $options, $arguments, &$world) { if (!isset($arguments[1])) { $action = 'show'; } else { $action = $arguments[1]; } if (!isset($arguments[2])) { $folder_name = 'INBOX'; } else { $folder_name = $arguments[2]; } switch ($action) { case 'create': if (!isset($arguments[3])) { $folder = $world['storage']->getList()->createFolder($folder_name); } else { $folder = $world['storage']->getList()->createFolder($folder_name, $arguments[3]); } $this->_showFolder($folder_name, $world, $cli); break; case 'rename': $folder = $world['storage']->getList()->renameFolder($folder_name, $arguments[3]); $this->_showFolder($arguments[3], $world, $cli); break; case 'delete': $folder = $world['storage']->getList()->deleteFolder($folder_name); break; case 'getacl': $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->getAcl($folder_name); $cli->writeln($folder_name); $cli->writeln(str_repeat('=', strlen($folder_name))); $pad = max(array_map('strlen', array_keys($acl))) + 2; foreach ($acl as $user => $rights) { $cli->writeln(Horde_String::pad($user . ':', $pad) . $rights); } break; case 'getmyacl': $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->getMyAcl($folder_name); $cli->writeln('Your rights on ' . $folder_name . ': ' . $acl); break; case 'setacl': $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->setAcl($folder_name, $arguments[3], $arguments[4]); break; case 'deleteacl': $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->deleteAcl($folder_name, $arguments[3]); break; case 'getdesc': $list = $world['storage']->getList(); $world['storage']->addListQuery($list, Horde_Kolab_Storage_List::QUERY_SHARE); $cli->writeln($list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)->getDescription($folder_name)); break; case 'setdesc': $list = $world['storage']->getList(); $world['storage']->addListQuery($list, Horde_Kolab_Storage_List::QUERY_SHARE); $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)->setDescription($folder_name, $arguments[3]); break; case 'getshare': $list = $world['storage']->getList(); $world['storage']->addListQuery($list, Horde_Kolab_Storage_List::QUERY_SHARE); $parameters = $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)->getParameters($folder_name); $pad = max(array_map('strlen', array_keys($parameters))) + 2; foreach ($parameters as $key => $value) { $cli->writeln(Horde_String::pad($key . ':', $pad) . $value); } break; case 'show': $this->_showFolder($folder_name, $world, $cli); break; default: $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error'); break; } }