| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
class Phergie_Plugin_JoinPart extends Phergie_Plugin_Abstract_Command |
|---|
| 8 |
{ |
|---|
| 9 |
|
|---|
| 10 |
* Flag indicating whether or not the plugin is an admin plugin or not |
|---|
| 11 |
* |
|---|
| 12 |
* @var bool |
|---|
| 13 |
*/ |
|---|
| 14 |
public $needsAdmin = true; |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
* Joins the specified channel. |
|---|
| 18 |
* |
|---|
| 19 |
* @param string $channel Name of the channel to join |
|---|
| 20 |
*/ |
|---|
| 21 |
public function onDoJoin($channel) |
|---|
| 22 |
{ |
|---|
| 23 |
if (!empty($channel)) { |
|---|
| 24 |
$channel = preg_replace('/,\s+/', ',', trim($channel)); |
|---|
| 25 |
$this->doJoin($channel); |
|---|
| 26 |
} |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
* Parts either the specified channel or the channel from which the |
|---|
| 31 |
* request originates if no channel is specified. |
|---|
| 32 |
* |
|---|
| 33 |
* @param string $channel Name of the channel to part (optional) |
|---|
| 34 |
* @param Phergie_Event_Request $event Intercepted event |
|---|
| 35 |
*/ |
|---|
| 36 |
public function onDoPart($channel = null) |
|---|
| 37 |
{ |
|---|
| 38 |
$source = $this->event->getSource(); |
|---|
| 39 |
$channel = trim($channel); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
if (empty($channel) && $source[0] == '#') { |
|---|
| 43 |
$this->doPart($source); |
|---|
| 44 |
|
|---|
| 45 |
} else if (preg_match('/^([#&][^\s,]+ (?:\s*,+\s* [#&][^\s,]+)* | all | \#)?(?:[\s,]+)?(.*)?$/xis', $channel, $match)) { |
|---|
| 46 |
$channels = preg_replace(array('{\s}', '{,+}'), array('', ','), $match[1]); |
|---|
| 47 |
if (!empty($channels) || $source[0] == '#') { |
|---|
| 48 |
if (empty($channels) || $channels == '#') { |
|---|
| 49 |
if ($source[0] != '#') return; |
|---|
| 50 |
$channels = $source; |
|---|
| 51 |
} else if ($channels == 'all') { |
|---|
| 52 |
|
|---|
| 53 |
if (!$this->pluginLoaded('ServerInfo')) { |
|---|
| 54 |
|
|---|
| 55 |
$this->doJoin('0'); |
|---|
| 56 |
} else { |
|---|
| 57 |
$channels = implode(',', Phergie_Plugin_ServerInfo::getChannels()); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
$reason = trim($match[2]); |
|---|
| 62 |
if (substr($reason, 0, 1) === '(' && substr($reason, -1) === ')') { |
|---|
| 63 |
$reason = trim(substr($reason, 1, -1)); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
$this->doPart($channels, $reason); |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
unset($channel, $channels, $reason); |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|