| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
class Phergie_Plugin_ModuleList extends Phergie_Plugin_Abstract_Command |
|---|
| 11 |
{ |
|---|
| 12 |
|
|---|
| 13 |
* Flag indicating whether or not the plugin is an admin plugin or not |
|---|
| 14 |
* |
|---|
| 15 |
* @var bool |
|---|
| 16 |
*/ |
|---|
| 17 |
public $needsAdmin = true; |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
* An array containing a list of arguments as the array's keys that are |
|---|
| 21 |
* available and the value is what the argurment is mapped to. |
|---|
| 22 |
* |
|---|
| 23 |
* @var array |
|---|
| 24 |
*/ |
|---|
| 25 |
protected $argList = array( |
|---|
| 26 |
'v' => 'Verbose', |
|---|
| 27 |
'e' => 'Enabled', |
|---|
| 28 |
'd' => 'Disabled', |
|---|
| 29 |
'm' => 'Muted', |
|---|
| 30 |
'g' => 'Global_Muted', |
|---|
| 31 |
'l' => 'Local_Muted', |
|---|
| 32 |
'u' => 'Unmuted', |
|---|
| 33 |
'p' => 'Passive', |
|---|
| 34 |
'a' => 'Admin', |
|---|
| 35 |
'b' => 'Base', |
|---|
| 36 |
'i' => 'Inactive', |
|---|
| 37 |
); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
* An array containing a list of states to display on the verbose plugin |
|---|
| 41 |
* list. The keys are the values from $argList and the values are the |
|---|
| 42 |
* letters to append to the verbose list. |
|---|
| 43 |
* |
|---|
| 44 |
* @var array |
|---|
| 45 |
*/ |
|---|
| 46 |
protected $verboseList = array( |
|---|
| 47 |
'Admin' => 'A', |
|---|
| 48 |
'Disabled' => 'D', |
|---|
| 49 |
'Local_Muted' => 'L', |
|---|
| 50 |
'Global_Muted' => 'G', |
|---|
| 51 |
'Passive' => 'P', |
|---|
| 52 |
'Inactive' => 'I' |
|---|
| 53 |
); |
|---|
| 54 |
|
|---|
| 55 |
public function onDoPlugins($rawArgs = '') |
|---|
| 56 |
{ |
|---|
| 57 |
$source = $this->event->getSource(); |
|---|
| 58 |
$rawArgs = $this->parseArguments($rawArgs); |
|---|
| 59 |
$target = trim(strtolower(!empty($rawArgs['strings'][0]) && $this->fromAdmin(true) ? $rawArgs['strings'][0] : $source)); |
|---|
| 60 |
$pluginData = array(); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
$args = array(); |
|---|
| 64 |
foreach($rawArgs['flags'] as $arg => $value) { |
|---|
| 65 |
if ($arg == 'mg' || $arg == 'mutedglobal') $arg = 'g'; |
|---|
| 66 |
else if ($arg == 'ml' || $arg == 'mutedlocal') $arg = 'l'; |
|---|
| 67 |
$args[substr(strtolower($arg), 0, 1)] = $value; |
|---|
| 68 |
} |
|---|
| 69 |
unset($rawArgs); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
if (isset($args['h'])) { |
|---|
| 73 |
$message = 'Help Info: '; |
|---|
| 74 |
foreach($this->argList as $arg => $info) { |
|---|
| 75 |
|
|---|
| 76 |
$message .= '-'.$arg.', -'.str_replace('_','',strtolower($info)).' = '. |
|---|
| 77 |
str_replace('_',' ',ucfirst($info)).' '.($arg == 'v'?'mode':'plugins').' | '; |
|---|
| 78 |
} |
|---|
| 79 |
$this->doPrivmsg($source, trim($message, "| \t\n\r\0\v\0xa0")); |
|---|
| 80 |
return; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
$plugins = $this->getPluginList(true); |
|---|
| 85 |
foreach($plugins as $plugin) { |
|---|
| 86 |
$plugin = ucfirst(trim($plugin)); |
|---|
| 87 |
if (!empty($plugin)) { |
|---|
| 88 |
$data = $this->getPlugin($plugin); |
|---|
| 89 |
if ($data) { |
|---|
| 90 |
|
|---|
| 91 |
if ($data->enabled) { |
|---|
| 92 |
$pluginData['Enabled'][] = $plugin; |
|---|
| 93 |
} else { |
|---|
| 94 |
$pluginData['Disabled'][] = $plugin; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
if (!empty($data->muted[$target]) || !empty($data->muted['global'])) { |
|---|
| 99 |
$pluginData['Muted'][] = $plugin . (!empty($data->muted['global']) ? '*' : ''); |
|---|
| 100 |
if (!empty($data->muted['global'])) { |
|---|
| 101 |
$pluginData['Global_Muted'][] = $plugin; |
|---|
| 102 |
} |
|---|
| 103 |
if (!empty($data->muted[$target])) { |
|---|
| 104 |
$pluginData['Local_Muted'][] = $plugin; |
|---|
| 105 |
} |
|---|
| 106 |
} else { |
|---|
| 107 |
$pluginData['Unmuted'][] = $plugin; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
if ($data->needsAdmin) { |
|---|
| 112 |
$pluginData['Admin'][] = $plugin; |
|---|
| 113 |
} else { |
|---|
| 114 |
$pluginData['Base'][] = $plugin; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
if ($data->passive) { |
|---|
| 119 |
$pluginData['Passive'][] = $plugin; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
$pluginData['Plugins'][] = $plugin; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
else { |
|---|
| 127 |
$pluginData['Inactive'][] = $plugin; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
$state = null; |
|---|
| 132 |
if (isset($args['v']) && is_array($pluginData)) { |
|---|
| 133 |
foreach($this->verboseList as $key => $value) { |
|---|
| 134 |
if (isset($pluginData[$key]) and is_array($pluginData[$key]) && |
|---|
| 135 |
in_array($plugin, $pluginData[$key])) { |
|---|
| 136 |
$state .= $value; |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
$pluginData['Verbose'][] = $plugin . (!empty($state) ? '(' . trim($state) . ')' : ''); |
|---|
| 141 |
} |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
unset($plugins); |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
$message = null; |
|---|
| 148 |
if (!isset($args['v']) && is_array($args) && count($args) > 0) { |
|---|
| 149 |
foreach($args as $arg => $value) { |
|---|
| 150 |
$plugin = $this->argList[$arg]; |
|---|
| 151 |
if (isset($plugin)) { |
|---|
| 152 |
if (is_array($pluginData[$plugin]) && count($pluginData[$plugin]) > 0) { |
|---|
| 153 |
sort($pluginData[$plugin]); |
|---|
| 154 |
} |
|---|
| 155 |
$plugins = trim(count($pluginData[$plugin]) > 0 ? implode(', ', $pluginData[$plugin]) : ''); |
|---|
| 156 |
$message .= ucfirst(str_replace('_', ' ', $plugin)) . ': ' . ($plugins ? $plugins : 'No Plugins') . ' :: '; |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|
| 159 |
unset($plugins); |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
if (empty($message)) { |
|---|
| 164 |
$display = (isset($args['v']) ? 'Verbose' : 'Plugins'); |
|---|
| 165 |
if (is_array($pluginData[$display])) { |
|---|
| 166 |
sort($pluginData[$display]); |
|---|
| 167 |
$message = $display . ': ' . implode(', ', $pluginData[$display]); |
|---|
| 168 |
} |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
$this->doPrivmsg($source, trim($message, ": \t\n\r\0\v\0xa0")); |
|---|
| 172 |
unset($message); |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|