-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.CommandMenu.php
More file actions
145 lines (126 loc) · 3.67 KB
/
class.CommandMenu.php
File metadata and controls
145 lines (126 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Abstract class Command representing a command in a command menu
*/
class Command {
var $text;
var $enabled;
function __construct($text, $enabled, $sep=true) {
//$this->text = str_replace(" ", " ", $text); don't need to do this because we're using <nobr></nobr> tags
//<nobr> should not be used. it isn't a valid html tag.
$this->text = $text;
$this->enabled = $enabled;
$this->wantsep = $sep;
}
function toString() {
if (!$this->enabled)
return "<nobr><span class=\"command_current\">$this->text</span></nobr>";
//NOBR is not a valid html tag
/**
*@todo - find a way to replace the nobr tags whilst keeping the menu icons next to the names
*/
else
return $this->text;
}
function setEnabled($enabled) {
$this->enabled = $enabled;
}
}
/* A class which represents a single command in a command menu.
* It has a url and a visual reprenstation (text)
*/
class TextCommand extends Command {
var $url;
/**
* Constructor
*/
function __construct($text, $enabled, $url) {
parent::__construct($text, $enabled);
$this->url = $url;
}
function toString() {
if (!$this->enabled)
return parent::toString();
else
return "<nobr><a href=\"" . $this->url . "\" class=\"command\">" . $this->text . "</a></nobr>";
//NOBR is not a valid html tag
/**
*@todo - find a way to replace the nobr tags whilst keeping the menu icons next to the names
*/
}
}
class IconTextCommand extends TextCommand {
var $img;
/**
* Constructor
*/
function __construct($text, $enabled, $url, $img) {
parent::__construct($text, $enabled, $url);
$this->img = $img;
}
function toString() {
if (!file_exists($this->img))
return parent::toString();
else
return "<nobr><a href=\"" . $this->url . "\" class=\"command\"><img src=\"" . $this->img . "\" alt=\"\" border=\"0\" align=\"absbottom\" />" . $this->text . "</a></nobr>";
//NOBR is not a valid html tag
/**
*@todo - find a way to replace the nobr tags whilst keeping the menu icons next to the names
*/
}
}
/* A class representing a menu of commands.
* It's responsible for printing the menu with a separator
*/
class CommandMenu {
//array which holds the commands in the menu
var $commands = array();
/* adds a command to the menu */
function add($command) {
$this->commands[] = $command;
}
/* returns the command menu as html */
function toString() {
$printedFirstCommand = false;
$returnString = "";
//iterate through commands
$count = count($this->commands);
for ($i=0; $i < $count; $i++) {
//append this command to the string
$returnString = $returnString . $this->commands[$i]->toString();
if($this->commands[$i]->wantsep)
$returnString = $returnString . " ";
}
//return the command menu as a string
return $returnString;
}
/**
* Disables a menu command with the given text
*/
function disableCommand($text) {
//iterate through commands
$count = count($this->commands);
for ($i=0; $i < $count; $i++) {
if ($this->commands[$i]->text == $text)
$this->commands[$i]->setEnabled(false);
}
}
function disableSelf() {
//iterate through commands
$count = count($this->commands);
for ($i=0; $i < $count; $i++) {
$self = $_SERVER["PHP_SELF"];
$slashPos = strrpos($self, "/");
if (!is_bool($slashPos))
$self = substr($self, $slashPos + 1);
$url = empty($this->commands[$i]->url) ? 'noURL' : $this->commands[$i]->url;
$pos = strpos($url, $self);
if (!is_bool($pos) && $pos == 0)
$this->commands[$i]->setEnabled(false);
}
}
}
//create the command menu object so that those files which include this one dont need to
$commandMenu = new CommandMenu;
// vim:ai:ts=4:sw=4
?>