FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
MicroMenu.php
1 <?php
2 
4 
5 class MicroMenu
6 {
7  const VIEW = 'View';
8  const VIEW_META = 'View-Meta';
9 
10  const FORMAT_HEX = 'hex';
11  const FORMAT_TEXT = 'text';
12  const FORMAT_FLOW = 'flow';
13 
14  const TARGET_DEFAULT = 'default';
15  const TARGET_VIEW = 'view';
16 
17  private $formatOptions = array(self::FORMAT_FLOW, self::FORMAT_TEXT, self::FORMAT_HEX);
18 
19  private $textFormats = array(self::FORMAT_HEX, self::FORMAT_TEXT, self::FORMAT_FLOW);
20 
21  private $targets = array(
22  self::TARGET_DEFAULT => array(MicroMenu::VIEW_META, MicroMenu::VIEW),
23  self::TARGET_VIEW => array(MicroMenu::VIEW)
24  );
25 
26  public function insert($groups, $name, $position, $module, $uri, $tooltip)
27  {
28  if (!is_array($groups)) {
29  $groups = $this->targets[$groups];
30  }
31 
32  $showLink = GetParm("mod", PARM_STRING) !== $module;
33 
34  foreach ($groups as $group) {
35  $menuKey = $group . MENU_PATH_SEPARATOR . $name;
36  if ($showLink) {
37  menu_insert($menuKey, $position, $uri, $tooltip);
38  } else {
39  menu_insert($menuKey, $position);
40  }
41  }
42  }
43 
48  public function getFormatParameter($itemId = null)
49  {
50  $selectedFormat = GetParm("format", PARM_STRING);
51 
52  if (in_array($selectedFormat, $this->formatOptions)) {
53  return $selectedFormat;
54  }
55  if (empty($itemId)) {
56  return self::FORMAT_FLOW;
57  } else {
58  $mimeType = GetMimeType($itemId);
59  list($type, $dummy) = explode("/", $mimeType, 2);
60  return $type == 'text' ? self::FORMAT_TEXT : self::FORMAT_FLOW;
61  }
62  }
63 
68  public function addFormatMenuEntries($selectedFormat, $pageNumber, $menuKey = self::VIEW, $hexFactor = 10)
69  {
70  $uri = Traceback_parm();
71  $uri = preg_replace("/&format=[a-zA-Z0-9]*/", "", $uri);
72  $uri = preg_replace("/&page=[0-9]*/", "", $uri);
73 
74  $pageNumberHex = null;
75  $pageNumberText = null;
76 
77  $tooltipTexts = array(
78  self::FORMAT_HEX => _("View as a hex dump"),
79  self::FORMAT_TEXT => _("View as unformatted text"),
80  self::FORMAT_FLOW => _("View as formatted text")
81  );
82 
83  $menuTexts = array(
84  self::FORMAT_HEX => "Hex",
85  self::FORMAT_TEXT => "Text",
86  self::FORMAT_FLOW => "Formatted"
87  );
88 
89  $menuPosition = -9;
90  menu_insert("$menuKey::[BREAK]", $menuPosition--);
91 
92  foreach ($this->textFormats as $currentFormat) {
93  $menuName = $menuKey . MENU_PATH_SEPARATOR . $menuTexts[$currentFormat];
94  if ($currentFormat == $selectedFormat) {
95  menu_insert($menuName, $menuPosition--);
96  } else {
97  $targetPageNumber = $currentFormat == self::FORMAT_HEX ? $hexFactor * $pageNumberHex : $pageNumber;
98  menu_insert($menuName, $menuPosition--, "$uri&format=$currentFormat&pageNumber=$targetPageNumber", $tooltipTexts[$currentFormat]);
99  }
100  }
101  menu_insert("$menuKey::[BREAK]", $menuPosition);
102  }
103 }
Traceback_parm($ShowMod=1)
Get the URI query to this location.
addFormatMenuEntries($selectedFormat, $pageNumber, $menuKey=self::VIEW, $hexFactor=10)
Definition: MicroMenu.php:68
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
const PARM_STRING
Definition: common-parm.php:29
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item...
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
const MENU_PATH_SEPARATOR
Separator used between menu paths.
Definition: common-menu.php:22
GetMimeType($Item)
Given an uploadtree_pk, return a string that describes the mime type.
Definition: common-repo.php:36