<?php
namespace yii\adminUi\widget;

use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii;

/**
 * Bootstrap box component.
 *
 * @see http://getbootstrap.com/javascript/#dropdowns
 * @author Mithun Mandal <mithun12000@gmail.com>
 * @since 2.0
 */
class Box extends Widget
{
    const TYPE_SOLID = "box-solid";
    const TYPE_DANGER = "box-danger";
    const TYPE_INFO = "box-info";
    const TYPE_PRIMARY = "box-primary";
    const TYPE_SUCCESS = "box-success";
    const TYPE_WARNING = "box-warning";
    const TYPE_DEFAULT = "";

    const POSITION_HEADER = 0;
    const POSITION_FOOTER = 1;

    /**
     * @var string the header content in the modal window.
     */
    public $header;

    public $headeroption = [];

    public $template = '{collapse} {remove}';

    public $buttons = [];

    public $usebutton = false;
    public $usebuttonPosition = self::POSITION_HEADER;

    public $buttonoption = [];

    public $bodytoption = [];

    public $headerIcon;

    public $headerButton;

    public $headerButtonGroup;

    public $loading = false;
    /**
     * @var string the footer content in the modal window.
     */
    public $footer;
    /**
     * @var string the modal size. Can be MODAL_LG or MODAL_SM, or empty for default.
     */
    public $type;

    /**
     * Initializes the widget.
     */
    public function init()
    {
        parent::init();
        $this->initOptions();
        $this->initDefaultButtons();

        echo Html::beginTag('div', $this->options) . "\n";
        echo Html::beginTag('div', ['class' => 'box ' . $this->type]) . "\n";
        echo $this->renderHeader() . "\n";
        echo $this->renderBodyBegin() . "\n";
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        echo "\n" . $this->renderBodyEnd();
        if($this->loading){
            echo Html::tag('div','',['class'=>'overlay']);
            echo Html::tag('div','',['class'=>'loading-img']);
        }
        echo "\n" . $this->renderFooter();
        echo "\n" . Html::endTag('div'); // modal-content
        echo "\n" . Html::endTag('div');
    }

    /**
     * Renders the header HTML markup of the modal
     * @return string the rendering result
     */
    protected function renderHeader()
    {
        if ($this->header !== null) {
            $content = '';
            if($this->headerIcon !== null){
               $content .=  Html::tag('i', '', ['class' => $this->headerIcon]);
            }

            $content .=  Html::tag('h3', "\n" . $this->header . "\n", ['class' => 'box-title']);

            if($this->headerButton !== null){
               $content .=  Html::tag('div', $this->headerButton, ['class' => ($this->headerButtonGroup) ? 'pull-right box-tools btn-group':'pull-right box-tools']);
            }

            if($this->usebutton){
                $content .= $this->renderButton(self::POSITION_HEADER);
            }

            return Html::tag('div', $content, array_merge(['class' => 'box-header'],  $this->headeroption));
        } else {
            return null;
        }
    }

    /**
     * Renders the opening tag of the modal body.
     * @return string the rendering result
     */
    protected function renderBodyBegin()
    {
        return Html::beginTag('div', array_merge($this->bodytoption,['class' => 'box-body'.' '.$this->bodytoption['class']]));
    }

    /**
     * Renders the closing tag of the modal body.
     * @return string the rendering result
     */
    protected function renderBodyEnd()
    {
        return Html::endTag('div');
    }

    /**
     * Renders the HTML markup for the footer of the modal
     * @return string the rendering result
     */
    protected function renderFooter()
    {
        if ($this->footer !== null) {
            $content = $this->footer;
            if($this->usebutton){
                $content .= $this->renderButton(self::POSITION_FOOTER);
            }
            return Html::tag('div', "\n" . $content . "\n", ['class' => 'box-footer clearfix']);
        } else {
            return null;
        }
    }

    /**
     * Initializes the widget options.
     * This method sets the default values for various options.
     */
    protected function initOptions()
    {
        $this->options = array_merge([
            'class' => 'infobox',
        ], $this->options);
        //Html::addCssClass($this->options, 'modal');
    }

    /**
     * Initializes the default button rendering callbacks
     */
    protected function initDefaultButtons()
    {
        if (!isset($this->buttons['collapse'])) {
            $this->buttons['collapse'] = function ($option) {
                $option['class'] = 'btn '.$option['class'];
                $option['data-widget'] = 'collapse';
                $option['data-toggle'] = 'tooltip';
                $option['title'] = Yii::t('yii', 'Collapse');

                if($option['notitle']){
                    unset($option['notitle'],$option['title']);
                }

                return Html::tag('button','', $option);
            };
        }
        if (!isset($this->buttons['remove'])) {
            $this->buttons['remove'] = function ($option) {
                $option['class'] = 'btn '.$option['class'];
                $option['data-widget'] = 'remove';
                $option['data-toggle'] = 'tooltip';
                $option['title'] = Yii::t('yii', 'Remove');

                if($option['notitle']){
                    unset($option['notitle'],$option['title']);
                }
                return Html::tag('button','', $option);
            };
        }
    }

    /**
     * @inheritdoc
     */
    protected function rendertemplate($option)
    {
        return preg_replace_callback('/\\{([\w\-\/]+)\\}/', function ($matches) use ($option) {
            $name = $matches[1];
            if (isset($this->buttons[$name])) {
                return call_user_func($this->buttons[$name], $option);
            } else {
                return '';
            }
        }, $this->template);
    }

    protected function renderButton($position){
        if($this->usebuttonPosition == $position){
            $btns = $this->rendertemplate($this->buttonoption);
            return Html::tag('div', $btns, ['class' => 'pull-right box-tools']);
        }else{
            return '';
        }
    }
}


<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\adminUi\widget;
use yii;
use yii\helpers\Html;

/**
 * Button renders a bootstrap button.
 *
 * For example,
 *
 * ```php
 * echo Button::widget([
 *     'label' => 'Action',
 *     'options' => ['class' => 'btn-lg'],
 * ]);
 * ```
 * @see http://getbootstrap.com/javascript/#buttons
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @since 2.0
 */
class Button extends Widget
{
    /**
     * @var string the tag to use to render the button
     */
    public $tagName = 'button';
    /**
     * @var string the button label
     */
    public $label = 'Button';
    /**
     * @var boolean whether the label should be HTML-encoded.
     */
    public $encodeLabel = true;

    /**
     * Initializes the widget.
     * If you override this method, make sure you call the parent implementation first.
     */
    public function init()
    {
        parent::init();
        $this->clientOptions = false;
        Html::addCssClass($this->options, 'btn');
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        echo Html::tag($this->tagName, $this->encodeLabel ? Html::encode($this->label) : $this->label, $this->options);
        $this->registerPlugin('button');
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: Update.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Adapter;

use TeamSpeak3\Ts3Exception;
use TeamSpeak3\Helper\Profiler;
use TeamSpeak3\Helper\Signal;
use TeamSpeak3\Helper\StringHelper;
use TeamSpeak3\Transport\AbstractTransport;

/**
 * @class Update
 * @brief Provides methods to query the latest TeamSpeak 3 build numbers from the master server.
 */
class Update extends AbstractAdapter
{
    /**
     * The IPv4 address or FQDN of the TeamSpeak Systems update server.
     *
     * @var string
     */
    protected $default_host = "update.teamspeak.com";

    /**
     * The UDP port number of the TeamSpeak Systems update server.
     *
     * @var integer
     */
    protected $default_port = 17384;

    /**
     * Stores an array containing the latest build numbers (integer timestamps).
     *
     * @var array
     */
    protected $build_datetimes = null;

    /**
     * Stores an array containing the latest version strings.
     *
     * @var array
     */
    protected $version_strings = null;

    /**
     * Connects the AbstractTransport object and performs initial actions on the remote
     * server.
     *
     * @throws Ts3Exception
     * @return void
     */
    public function syn()
    {
        if (!isset($this->options["host"]) || empty($this->options["host"])) {
            $this->options["host"] = $this->default_host;
        }
        if (!isset($this->options["port"]) || empty($this->options["port"])) {
            $this->options["port"] = $this->default_port;
        }

        $this->initTransport($this->options, "UDP");
        $this->transport->setAdapter($this);

        Profiler::init(spl_object_hash($this));

        $this->getTransport()->send(StringHelper::fromHex(33));

        if (!preg_match_all(
                "/,?(\d+)#([0-9a-zA-Z\._-]+),?/",
                $this->getTransport()->read(96),
                $matches
            ) || !isset($matches[1]) || !isset($matches[2])
        ) {
            throw new Ts3Exception("invalid reply from the server");
        }

        $this->build_datetimes = $matches[1];
        $this->version_strings = $matches[2];

        Signal::getInstance()->emit("updateConnected", $this);
    }

    /**
     * The Update destructor.
     *
     * @return void
     */
    public function __destruct()
    {
        if ($this->getTransport() instanceof AbstractTransport && $this->getTransport()->isConnected()) {
            $this->getTransport()->disconnect();
        }
    }

    /**
     * Returns the current build number for a specified update channel. Note that since version
     * 3.0.0, the build number represents an integer timestamp. $channel must be set to one of
     * the following values:
     *
     * - stable
     * - beta
     * - alpha
     * - server
     *
     * @param  string $channel
     * @throws Ts3Exception
     * @return integer
     */
    public function getRev($channel = "stable")
    {
        switch ($channel) {
            case "stable":
                return isset($this->build_datetimes[0]) ? $this->build_datetimes[0] : null;

            case "beta":
                return isset($this->build_datetimes[1]) ? $this->build_datetimes[1] : null;

            case "alpha":
                return isset($this->build_datetimes[2]) ? $this->build_datetimes[2] : null;

            case "server":
                return isset($this->build_datetimes[3]) ? $this->build_datetimes[3] : null;

            default:
                throw new Ts3Exception("invalid update channel identifier (" . $channel . ")");
        }
    }

    /**
     * Returns the current version string for a specified update channel. $channel must be set to
     * one of the following values:
     *
     * - stable
     * - beta
     * - alpha
     * - server
     *
     * @param  string $channel
     * @throws Ts3Exception
     * @return integer
     */
    public function getVersion($channel = "stable")
    {
        switch ($channel) {
            case "stable":
                return isset($this->version_strings[0]) ? $this->version_strings[0] : null;

            case "beta":
                return isset($this->version_strings[1]) ? $this->version_strings[1] : null;

            case "alpha":
                return isset($this->version_strings[2]) ? $this->version_strings[2] : null;

            case "server":
                return isset($this->version_strings[3]) ? $this->version_strings[3] : null;

            default:
                throw new Ts3Exception("invalid update channel identifier (" . $channel . ")");
        }
    }

    /**
     * Alias for getRev() using the 'stable' update channel.
     *
     * @internal param string $channel
     * @return integer
     */
    public function getClientRev()
    {
        return $this->getRev("stable");
    }

    /**
     * Alias for getRev() using the 'server' update channel.
     *
     * @return integer
     */
    public function getServerRev()
    {
        return $this->getRev("server");
    }

    /**
     * Alias for getVersion() using the 'stable' update channel.
     *
     * @return integer
     */
    public function getClientVersion()
    {
        return $this->getVersion("stable");
    }

    /**
     * Alias for getVersion() using the 'server' update channel.
     *
     * @return integer
     */
    public function getServerVersion()
    {
        return $this->getVersion("server");
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: Char.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Helper;

use TeamSpeak3\Ts3Exception;

/**
 * @class Char
 * @brief Helper class for char handling.
 */
class Char
{
    /**
     * Stores the original character.
     *
     * @var string
     */
    protected $char = null;

    /**
     * The Char constructor.
     *
     * @param $char
     * @throws Ts3Exception
     * @internal param string $var
     * @return Char
     */
    public function __construct($char)
    {
        if (strlen($char) != 1) {
            throw new Ts3Exception("char parameter may not contain more or less than one character");
        }

        $this->char = strval($char);
    }

    /**
     * Returns true if the character is a letter.
     *
     * @return boolean
     */
    public function isLetter()
    {
        return ctype_alpha($this->char);
    }

    /**
     * Returns true if the character is a decimal digit.
     *
     * @return boolean
     */
    public function isDigit()
    {
        return ctype_digit($this->char);
    }

    /**
     * Returns true if the character is a space.
     *
     * @return boolean
     */
    public function isSpace()
    {
        return ctype_space($this->char);
    }

    /**
     * Returns true if the character is a mark.
     *
     * @return boolean
     */
    public function isMark()
    {
        return ctype_punct($this->char);
    }

    /**
     * Returns true if the character is a control character (i.e. "\t").
     *
     * @return boolean
     */
    public function isControl()
    {
        return ctype_cntrl($this->char);
    }

    /**
     * Returns true if the character is a printable character.
     *
     * @return boolean
     */
    public function isPrintable()
    {
        return ctype_print($this->char);
    }

    /**
     * Returns true if the character is the Unicode character 0x0000 ("\0").
     *
     * @return boolean
     */
    public function isNull()
    {
        return ($this->char === "\0") ? true : false;
    }

    /**
     * Returns true if the character is an uppercase letter.
     *
     * @return boolean
     */
    public function isUpper()
    {
        return ($this->char === strtoupper($this->char)) ? true : false;
    }

    /**
     * Returns true if the character is a lowercase letter.
     *
     * @return boolean
     */
    public function isLower()
    {
        return ($this->char === strtolower($this->char)) ? true : false;
    }

    /**
     * Returns the uppercase equivalent if the character is lowercase.
     *
     * @return Char
     */
    public function toUpper()
    {
        return ($this->isUpper()) ? $this : new self(strtoupper($this));
    }

    /**
     * Returns the lowercase equivalent if the character is uppercase.
     *
     * @return Char
     */
    public function toLower()
    {
        return ($this->isLower()) ? $this : new self(strtolower($this));
    }

    /**
     * Returns the ascii value of the character.
     *
     * @return integer
     */
    public function toAscii()
    {
        return ord($this->char);
    }

    /**
     * Returns the Unicode value of the character.
     *
     * @return integer
     */
    public function toUnicode()
    {
        $h = ord($this->char{0});

        if ($h <= 0x7F) {
            return $h;
        } else {
            if ($h < 0xC2) {
                return false;
            } else {
                if ($h <= 0xDF) {
                    return ($h & 0x1F) << 6 | (ord($this->char{1}) & 0x3F);
                } else {
                    if ($h <= 0xEF) {
                        return ($h & 0x0F) << 12 | (ord($this->char{1}) & 0x3F) << 6 | (ord($this->char{2}) & 0x3F);
                    } else {
                        if ($h <= 0xF4) {
                            return ($h & 0x0F) << 18 | (ord($this->char{1}) & 0x3F) << 12 | (ord(
                                    $this->char{2}
                                ) & 0x3F) << 6 | (ord(
                                    $this->char{3}
                                ) & 0x3F);
                        } else {
                            return false;
                        }
                    }
                }
            }
        }
    }

    /**
     * Returns the hexadecimal value of the char.
     *
     * @return string
     */
    public function toHex()
    {
        return strtoupper(dechex($this->toAscii()));
    }

    /**
     * Returns the Char based on a given hex value.
     *
     * @param  string $hex
     * @throws Ts3Exception
     * @return Char
     */
    public static function fromHex($hex)
    {
        if (strlen($hex) != 2) {
            throw new Ts3Exception("given parameter '" . $hex . "' is not a valid hexadecimal number");
        }

        return new self(chr(hexdec($hex)));
    }

    /**
     * Returns the character as a standard string.
     *
     * @return string
     */
    public function toString()
    {
        return $this->char;
    }

    /**
     * Returns the integer value of the character.
     *
     * @return integer
     */
    public function toInt()
    {
        return intval($this->char);
    }

    /**
     * Returns the character as a standard string.
     *
     * @return string
     */
    public function __toString()
    {
        return $this->char;
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: FileTransfer.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Adapter;

use TeamSpeak3\Helper\Profiler;
use TeamSpeak3\Helper\Signal;
use TeamSpeak3\Transport\AbstractTransport;
use TeamSpeak3\Ts3Exception;
use TeamSpeak3\Helper\StringHelper;

/**
 * @class FileTransfer
 * @brief Provides low-level methods for file transfer communication with a TeamSpeak 3 Server.
 */
class FileTransfer extends AbstractAdapter
{
    /**
     * Connects the AbstractTransport object and performs initial actions on the remote
     * server.
     *
     * @throws Ts3Exception
     * @return void
     */
    public function syn()
    {
        $this->initTransport($this->options);
        $this->transport->setAdapter($this);

        Profiler::init(spl_object_hash($this));

        Signal::getInstance()->emit("filetransferConnected", $this);
    }

    /**
     * The FileTransfer destructor.
     *
     * @return void
     */
    public function __destruct()
    {
        if ($this->getTransport() instanceof AbstractTransport && $this->getTransport()->isConnected()) {
            $this->getTransport()->disconnect();
        }
    }

    /**
     * Sends a valid file transfer key to the server to initialize the file transfer.
     *
     * @param  string $ftkey
     * @throws Ts3Exception
     * @return void
     */
    protected function init($ftkey)
    {
        if (strlen($ftkey) != 32) {
            throw new Ts3Exception("invalid file transfer key format");
        }

        $this->getProfiler()->start();
        $this->getTransport()->send($ftkey);

        Signal::getInstance()->emit("filetransferHandshake", $this);
    }

    /**
     * Sends the content of a file to the server.
     *
     * @param  string $ftkey
     * @param  integer $seek
     * @param  string $data
     * @throws Ts3Exception
     * @return void
     */
    public function upload($ftkey, $seek, $data)
    {
        $this->init($ftkey);

        $size = strlen($data);
        $seek = intval($seek);
        $pack = 4096;

        Signal::getInstance()->emit("filetransferUploadStarted", $ftkey, $seek, $size);

        for (; $seek < $size;) {
            $rest = $size - $seek;
            $pack = $rest < $pack ? $rest : $pack;
            $buff = substr($data, $seek, $pack);
            $seek = $seek + $pack;

            $this->getTransport()->send($buff);

            Signal::getInstance()->emit("filetransferUploadProgress", $ftkey, $seek, $size);
        }

        $this->getProfiler()->stop();

        Signal::getInstance()->emit("filetransferUploadFinished", $ftkey, $seek, $size);

        if ($seek < $size) {
            throw new Ts3Exception(
                "incomplete file upload (" . $seek . " of " . $size . " bytes)"
            );
        }
    }

    /**
     * Returns the content of a downloaded file as a String object.
     *
     * @param  string $ftkey
     * @param  integer $size
     * @param  boolean $passthru
     * @throws Ts3Exception
     * @return StringHelper|void
     */
    public function download($ftkey, $size, $passthru = false)
    {
        $this->init($ftkey);

        if ($passthru) {
            return $this->passthru($size);
        }

        $buff = new StringHelper("");
        $size = intval($size);
        $pack = 4096;

        Signal::getInstance()->emit("filetransferDownloadStarted", $ftkey, count($buff), $size);

        for ($seek = 0; $seek < $size;) {
            $rest = $size - $seek;
            $pack = $rest < $pack ? $rest : $pack;
            $data = $this->getTransport()->read($rest < $pack ? $rest : $pack);
            $seek = $seek + $pack;

            $buff->append($data);

            Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size);
        }

        $this->getProfiler()->stop();

        Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size);

        if (strlen($buff) != $size) {
            throw new Ts3Exception(
                "incomplete file download (" . count($buff) . " of " . $size . " bytes)"
            );
        }

        return $buff;
    }

    /**
     * Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP's fpassthru()
     * function.
     *
     * @param  integer $size
     * @throws Ts3Exception
     * @return void
     */
    protected function passthru($size)
    {
        $buff_size = fpassthru($this->getTransport()->getStream());

        if ($buff_size != $size) {
            throw new Ts3Exception(
                "incomplete file download (" . intval($buff_size) . " of " . $size . " bytes)"
            );
        }
    }
}


<?php

namespace VPS;

class MailChimp
{

    private $apiKey;
    private $apiUrl = 'https://<dc>.api.mailchimp.com/3.0/';

    /**
    * Create a new instance
    * @param string $apiKey - Optional
    */
    public function __construct($apiKey = false)
    {
        if ($apiKey) {
            $this->apiKey = $apiKey;
            list(, $datacentre) = explode('-', $this->apiKey);
            $this->apiUrl = str_replace('<dc>', $datacentre, $this->apiUrl);
        }
    }

    /**
    * Method to Set Api Key
    * @param string $apiKey
    */
    public function setApiKey($apiKey)
    {
        $this->apiKey = $apiKey;
        list(, $datacentre) = explode('-', $this->apiKey);
        $this->apiUrl = str_replace('<dc>', $datacentre, $this->apiUrl);
    }

    /**
    * Magic Method to request http verb
    * @return array
    */
    public function __call($method, $arguments)
    {
        $httpVerb = strtoupper($method);
        $allowedHttpVerbs = array('GET', 'POST', 'PUT', 'PATCH', 'DELETE');

        //Validate http verb
        if (in_array($httpVerb, $allowedHttpVerbs)) {
            $endPoint = $arguments[0];
            $data = isset($arguments[1]) ? $arguments[1] : array();
            return $this->request($endPoint, $httpVerb, $data);
        }

        throw new \Exception('Invalid http verb!');
    }

    /**
    * Call MailChimp API
    * @param string $endPoint - (http://kb.mailchimp.com/api/resources)
    * @param string $httpVerb
    * @param array $data - Optional
    * @return array
    */
    public function request($endPoint, $httpVerb = 'GET', $data = array())
    {
        // Validate API
        if (!$this->apiKey) {
            throw new \Exception('MailChimp API Key must be set before making request!');
        }

        $endPoint = ltrim($endPoint, '/');
        $httpVerb = strtoupper($httpVerb);
        $requestUrl = $this->apiUrl.$endPoint;

        return $this->curlRequest($requestUrl, $httpVerb, $data);
    }

    /**
    * Request using curl extension
    * @param string $url
    * @param string $httpVerb
    * @param array $data - Optional
    * @return array
    */
    private function curlRequest($url, $httpVerb, array $data = array(), $curlTimeout = 15)
    {
        if (function_exists('curl_init') && function_exists('curl_setopt')) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_USERAGENT, 'VPS/MC-API:3.0');
            curl_setopt($ch, CURLOPT_TIMEOUT, $curlTimeout);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_USERPWD, "user:".$this->apiKey);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpVerb);

            //Submit data
            if (!empty($data)) {
                $jsonData = json_encode($data);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
            }

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec($ch);
            curl_close($ch);

            return $result ? json_decode($result, true) : false;
        }

        throw new \Exception('curl extension is missing!');
    }
}


<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\adminUi\widget;

use Yii;
use yii\adminUi\assetsBundle\AdminUiAsset as AdminUiAsset;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/**
 * Nav renders a nav HTML component.
 *
 * For example:
 *
 * ```php
 * echo Nav::widget([
 *     'items' => [
 *         [
 *             'label' => 'Home',
 *             'url' => ['site/index'],
 *             'linkOptions' => [...],
 *         ],
 *         [
 *             'label' => 'Dropdown',
 *             'items' => [
 *                  ['label' => 'Level 1 - Dropdown A', 'url' => '#'],
 *                  '<li class="divider"></li>',
 *                  '<li class="dropdown-header">Dropdown Header</li>',
 *                  ['label' => 'Level 1 - Dropdown B', 'url' => '#'],
 *             ],
 *         ],
 *     ],
 * ]);
 * ```
 *
 * Note: Multilevel dropdowns beyond Level 1 are not supported in Bootstrap 3.
 *
 * @see http://getbootstrap.com/components/#dropdowns
 * @see http://getbootstrap.com/components/#nav
 *
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @since 2.0
 */
class Nav extends Widget
{
    /**
     * @var array list of items in the nav widget. Each array element represents a single
     * menu item which can be either a string or an array with the following structure:
     *
     * - label: string, required, the nav item label.
     * - url: optional, the item's URL. Defaults to "#".
     * - visible: boolean, optional, whether this menu item is visible. Defaults to true.
     * - linkOptions: array, optional, the HTML attributes of the item's link.
     * - options: array, optional, the HTML attributes of the item container (LI).
     * - active: boolean, optional, whether the item should be on active state or not.
     * - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget,
     *   or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
     *
     * If a menu item is a string, it will be rendered directly without HTML encoding.
     */
    public $items = [];
    /**
     * @var boolean whether the nav items labels should be HTML-encoded.
     */
    public $encodeLabels = true;
    /**
     * @var boolean whether to automatically activate items according to whether their route setting
     * matches the currently requested route.
     * @see isItemActive
     */
    public $activateItems = true;
    /**
     * @var boolean whether to activate parent menu items when one of the corresponding child menu items is active.
     */
    public $activateParents = false;
    /**
     * @var string the route used to determine if a menu item is active or not.
     * If not set, it will use the route of the current request.
     * @see params
     * @see isItemActive
     */
    public $route;
    /**
     * @var array the parameters used to determine if a menu item is active or not.
     * If not set, it will use `$_GET`.
     * @see route
     * @see isItemActive
     */
    public $params;

    /**
     * Initializes the widget.
     */
    public function init()
    {
        parent::init();
        if ($this->route === null && Yii::$app->controller !== null) {
            $this->route = Yii::$app->controller->getRoute();
        }
        if ($this->params === null) {
            $this->params = Yii::$app->request->getQueryParams();
        }
        Html::addCssClass($this->options, 'nav');
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        echo $this->renderItems();
        AdminUiAsset::register($this->getView());
    }

    /**
     * Renders widget items.
     */
    public function renderItems()
    {
        $items = [];
        foreach ($this->items as $i => $item) {
            if (isset($item['visible']) && !$item['visible']) {
                unset($items[$i]);
                continue;
            }
            $items[] = $this->renderItem($item);
        }

        return Html::tag('ul', implode("\n", $items), $this->options);
    }

    /**
     * Renders a widget's item.
     * @param string|array $item the item to render.
     * @return string the rendering result.
     * @throws InvalidConfigException
     */
    public function renderItem($item)
    {
        if (is_string($item)) {
            return $item;
        }
        if(isset($item['content'])){
            return Html::tag('li', $item['content'], $item['options']);
        }
        if (!isset($item['label'])) {
            throw new InvalidConfigException("The 'label' option is required.");
        }
        $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
        $options = ArrayHelper::getValue($item, 'options', []);
        $items = ArrayHelper::getValue($item, 'items');
        $url = ArrayHelper::getValue($item, 'url', '#');
        $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
        $badgeOptions = ArrayHelper::getValue($item, 'badgeOptions', []);

        if (isset($item['active'])) {
            $active = ArrayHelper::remove($item, 'active', false);
        } else {
            $active = $this->isItemActive($item);
        }

        if ($items !== null) {
            //$linkOptions['data-toggle'] = 'treeview';
            Html::addCssClass($options, 'treeview');
            //Html::addCssClass($linkOptions, 'treeview-menu');
            //$label .= ' ' . Html::tag('i', '', ['class' => 'fa fa-angle-left pull-right']);
            if (is_array($items)) {
                if ($this->activateItems) {
                    $items = $this->isChildActive($items, $active);
                }
                $items = Dropdown::widget([
                    'items' => $items,
                    'encodeLabels' => $this->encodeLabels,
                    'clientOptions' => false,
                    'type' => Dropdown::NAV,
                    'view' => $this->getView(),
                ]);
            }
        }

        if ($this->activateItems && $active) {
            Html::addCssClass($options, 'active');
        }

        $label = Html::tag('i', '', $linkOptions).Html::tag('span', $label);
        $label .= $this->renderBadge($badgeOptions);
        if ($items !== null) {
            $label .= Html::tag('i', '', ['class' => 'fa fa-angle-left pull-right']);
        }

        return Html::tag('li', Html::a($label, $url) . $items, $options);
    }

    /**
     * Check to see if a child item is active optionally activating the parent.
     * @param array $items @see items
     * @param boolean $active should the parent be active too
     * @return array @see items
     */
    protected function isChildActive($items, &$active)
    {
        foreach ($items as $i => $child) {
            if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) {
                Html::addCssClass($items[$i]['options'], 'active');
                if ($this->activateParents) {
                    $active = true;
                }
            }
        }
        return $items;
    }

    /**
     * Checks whether a menu item is active.
     * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
     * When the `url` option of a menu item is specified in terms of an array, its first element is treated
     * as the route for the item and the rest of the elements are the associated parameters.
     * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
     * be considered active.
     * @param array $item the menu item to be checked
     * @return boolean whether the menu item is active
     */
    protected function isItemActive($item)
    {
        if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
            $route = $item['url'][0];
            if ($route[0] !== '/' && Yii::$app->controller) {
                $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
            }
            if (ltrim($route, '/') !== $this->route) {
                return false;
            }
            unset($item['url']['#']);
            if (count($item['url']) > 1) {
                foreach (array_splice($item['url'], 1) as $name => $value) {
                    if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                        return false;
                    }
                }
            }

            return true;
        }

        return false;
    }
}


<?php

namespace yii\adminUi\widget;

use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\base\InvalidConfigException;
use yii\adminUi\assetsBundle\AdminUIMultiselect;
use yii\helpers\Html;

/**
 * Dynamic form element based on Dynamic form Jquery plugin
 *
 */
class Multiselect extends InputWidget
{
    public $type = 'dropDownList';

    public $data = [];

    public $list = true;

    public $mask = '';
    public $maskType = '';

    /**
     * Initializes the widget
     *
     * @throw InvalidConfigException
     */
    public function init(){
        parent::init();
        //$this->options = array_merge($this->options,['readonly'=>'true']);
        if($this->data){
            $order = 0;
            if(is_array($this->model->{$this->attribute})){
                //echo '<pre>';
                //print_r($this->model->{$this->attribute});die;
                foreach($this->model->{$this->attribute} as $value){
                    $order++;
                    if(is_object($value)){
                        $this->options['options'][$value->Id] = ['data-order' => $order];
                    }else{
                        $this->options['options'][$value] = ['data-order' => $order];
                    }
                }
            }
        }
    }

    public function run() {
        //$id = $this->getId();
        Html::addCssClass($this->options, "form-control");
        echo $this->getInput($this->type, $this->list);
        $this->registerAssets();
    }

    /**
     * Registers the needed assets
     */
    public function registerAssets(){
        $view = $this->getView();
        AdminUIMultiselect::register($view);
        //$id = $this->options['id'];
        $inputId = Html::getInputId($this->model,  $this->attribute);
        $js = '$("#'.$inputId.'").asmSelect({
				addItemTarget: \'bottom\',
				animate: true,
				highlight: false,
				sortable: true,
                                selectClass:"form-control asmSelect"
			});';

        $view->registerJs($js);
    }
}
?>


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: AbstractAdapter.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Adapter;

use TeamSpeak3\Ts3Exception;
use TeamSpeak3\Transport\TCP;
use TeamSpeak3\Transport\UDP;
use TeamSpeak3\Transport\AbstractTransport;
use TeamSpeak3\Helper\Profiler;
use TeamSpeak3\Helper\Profiler\Timer;

/**
 * @class AbstractAdapter
 * @brief Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server.
 */
abstract class AbstractAdapter
{
    /**
     * Stores user-provided options.
     *
     * @var array
     */
    protected $options = null;

    /**
     * Stores an AbstractTransport object.
     *
     * @var AbstractTransport
     */
    protected $transport = null;

    /**
     * The AbstractAdapter constructor.
     *
     * @param  array $options
     * @return AbstractAdapter
     */
    public function __construct(array $options)
    {
        $this->options = $options;

        if ($this->transport === null) {
            $this->syn();
        }
    }

    /**
     * The AbstractAdapter destructor.
     *
     * @return void
     */
    abstract public function __destruct();

    /**
     * Connects the AbstractTransport object and performs initial actions on the remote
     * server.
     *
     * @throws Ts3Exception
     * @return void
     */
    abstract protected function syn();

    /**
     * Commit pending data.
     *
     * @return array
     */
    public function __sleep()
    {
        return array("options");
    }

    /**
     * Reconnects to the remote server.
     *
     * @return void
     */
    public function __wakeup()
    {
        $this->syn();
    }

    /**
     * Returns the profiler timer used for this connection adapter.
     *
     * @return Timer
     */
    public function getProfiler()
    {
        return Profiler::get(spl_object_hash($this));
    }

    /**
     * Returns the transport object used for this connection adapter.
     *
     * @return AbstractTransport
     */
    public function getTransport()
    {
        return $this->transport;
    }

    /**
     * Loads the transport object object used for the connection adapter and passes a given set
     * of options.
     *
     * @param  array $options
     * @param  string $transport
     * @throws Ts3Exception
     * @return void
     */
    protected function initTransport($options, $transport = "TCP")
    {
        if (!is_array($options)) {
            throw new Ts3Exception("transport parameters must provided in an array");
        }
        if($transport == "TCP")
            $this->transport = new TCP($options);
        else
            $this->transport = new UDP($options);
    }

    /**
     * Returns the hostname or IPv4 address the underlying AbstractTransport object
     * is connected to.
     *
     * @return string
     */
    public function getTransportHost()
    {
        return $this->getTransport()->getConfig("host", "0.0.0.0");
    }

    /**
     * Returns the port number of the server the underlying AbstractTransport object
     * is connected to.
     *
     * @return string
     */
    public function getTransportPort()
    {
        return $this->getTransport()->getConfig("port", "0");
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: Blacklist.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Adapter;

use TeamSpeak3\Helper\Profiler;
use TeamSpeak3\Helper\Signal;
use TeamSpeak3\Transport\AbstractTransport;
use TeamSpeak3\Ts3Exception;

/**
 * @class Blacklist
 * @brief Provides methods to check if an IP address is currently blacklisted.
 */
class Blacklist extends AbstractAdapter
{
    /**
     * The IPv4 address or FQDN of the TeamSpeak Systems update server.
     *
     * @var string
     */
    protected $default_host = "blacklist.teamspeak.com";

    /**
     * The UDP port number of the TeamSpeak Systems update server.
     *
     * @var integer
     */
    protected $default_port = 17385;

    /**
     * Stores an array containing the latest build numbers.
     *
     * @var array
     */
    protected $build_numbers = null;

    /**
     * Connects the AbstractTransport object and performs initial actions on the remote
     * server.
     *
     * @return void
     */
    public function syn()
    {
        if (!isset($this->options["host"]) || empty($this->options["host"])) {
            $this->options["host"] = $this->default_host;
        }
        if (!isset($this->options["port"]) || empty($this->options["port"])) {
            $this->options["port"] = $this->default_port;
        }

        $this->initTransport($this->options, "UDP");
        $this->transport->setAdapter($this);

        Profiler::init(spl_object_hash($this));

        Signal::getInstance()->emit("blacklistConnected", $this);
    }

    /**
     * The Blacklist destructor.
     *
     * @return void
     */
    public function __destruct()
    {
        if ($this->getTransport() instanceof AbstractTransport && $this->getTransport()->isConnected()) {
            $this->getTransport()->disconnect();
        }
    }

    /**
     * Returns TRUE if a specified $host IP address is currently blacklisted.
     *
     * @param  string $host
     * @throws Ts3Exception
     * @return boolean
     */
    public function isBlacklisted($host)
    {
        if (ip2long($host) === false) {
            $addr = gethostbyname($host);

            if ($addr == $host) {
                throw new Ts3Exception("unable to resolve IPv4 address (" . $host . ")");
            }

            $host = $addr;
        }

        $this->getTransport()->send("ip4:" . $host);
        $repl = $this->getTransport()->read(1);
        $this->getTransport()->disconnect();

        if (!count($repl)) {
            return false;
        }

        return ($repl->toInt()) ? false : true;
    }
}


<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\adminUi\widget;

use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/**
 * Dropdown renders a Bootstrap dropdown menu component.
 *
 * @see http://getbootstrap.com/javascript/#dropdowns
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @since 2.0
 */
class Dropdown extends Widget
{
    const NAV = 1;
    const DROPDOWN = 2;

    const DEFAULTTYEP = self::DROPDOWN;

    /**
     * @var array list of menu items in the dropdown. Each array element can be either an HTML string,
     * or an array representing a single menu with the following structure:
     *
     * - label: string, required, the label of the item link
     * - url: string, optional, the url of the item link. Defaults to "#".
     * - visible: boolean, optional, whether this menu item is visible. Defaults to true.
     * - linkOptions: array, optional, the HTML attributes of the item link.
     * - options: array, optional, the HTML attributes of the item.
     * - items: array, optional, the submenu items. The structure is the same as this property.
     *   Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
     *
     * To insert divider use `<li role="presentation" class="divider"></li>`.
     */
    public $items = [];
    /**
     * @var boolean whether the labels for header items should be HTML-encoded.
     */
    public $encodeLabels = true;

    /**
     * @var string droupdown type.
     */
    public $type;

    /**
     * Initializes the widget.
     * If you override this method, make sure you call the parent implementation first.
     */
    public function init()
    {
        parent::init();
        if($this->type){
            $class = ($this->type == self::DROPDOWN) ? 'dropdown-menu' : 'treeview-menu';
            Html::addCssClass($this->options,$class);
        }else{
            Html::addCssClass($this->options, 'dropdown-menu');
        }
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        echo $this->renderItems($this->items);
        $this->registerPlugin('dropdown');
    }

    /**
     * Renders menu items.
     * @param array $items the menu items to be rendered
     * @return string the rendering result.
     * @throws InvalidConfigException if the label option is not specified in one of the items.
     */
    protected function renderItems($items)
    {
        $lines = [];
        foreach ($items as $i => $item) {
            if (isset($item['visible']) && !$item['visible']) {
                unset($items[$i]);
                continue;
            }
            if (is_string($item)) {
                $lines[] = $item;
                continue;
            }

            $options = ArrayHelper::getValue($item, 'options', []);

            if(isset($item['divider'])){
                Html::addCssClass($options, 'divider');
                $lines[] = Html::tag('li','', $options);
                continue;
            }

            if (!isset($item['label'])) {
                throw new InvalidConfigException("The 'label' option is required.");
            }
            $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
            $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
            $linkOptions['tabindex'] = '-1';
            $badgeOptions = ArrayHelper::getValue($item, 'badgeOptions', []);

            $label = Html::tag('i', '', $linkOptions).Html::tag('span', $label);
            $label .= $this->renderBadge($badgeOptions);

            $content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'));
            if (!empty($item['items'])) {
                $content .= $this->renderItems($item['items']);
                Html::addCssClass($options, 'dropdown-submenu');
            }
            $lines[] = Html::tag('li', $content, $options);
        }

        return Html::tag('ul', implode("\n", $lines), $this->options);
    }
}


<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\adminUi\widget;

use Yii;
use yii\helpers\Json;
use yii\adminUi\assetsBundle\AdminUiAsset as AdminUiAsset;
use yii\helpers\Html;

/**
 * \yii\bootstrap\Widget is the base class for all bootstrap widgets.
 *
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class Widget extends \yii\base\Widget
{
    /**
     * @var array the HTML attributes for the widget container tag.
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
     */
    public $options = [];
    /**
     * @var array the options for the underlying Bootstrap JS plugin.
     * Please refer to the corresponding Bootstrap plugin Web page for possible options.
     * For example, [this page](http://getbootstrap.com/javascript/#modals) shows
     * how to use the "Modal" plugin and the supported options (e.g. "remote").
     */
    public $clientOptions = [];
    /**
     * @var array the event handlers for the underlying Bootstrap JS plugin.
     * Please refer to the corresponding Bootstrap plugin Web page for possible events.
     * For example, [this page](http://getbootstrap.com/javascript/#modals) shows
     * how to use the "Modal" plugin and the supported events (e.g. "shown").
     */
    public $clientEvents = [];

    /**
     * Initializes the widget.
     * This method will register the bootstrap asset bundle. If you override this method,
     * make sure you call the parent implementation first.
     */
    public function init()
    {
        parent::init();
        if (!isset($this->options['id'])) {
            $this->options['id'] = $this->getId();
        }
    }

    /**
     * Registers a specific Bootstrap plugin and the related events
     * @param string $name the name of the Bootstrap plugin
     */
    protected function registerPlugin($name)
    {
        $view = $this->getView();

        AdminUiAsset::register($view);

        $id = $this->options['id'];

        if ($this->clientOptions !== false) {
            $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
            $js = "jQuery('#$id').$name($options);";
            $view->registerJs($js);
        }

        if (!empty($this->clientEvents)) {
            $js = [];
            foreach ($this->clientEvents as $event => $handler) {
                $js[] = "jQuery('#$id').on('$event', $handler);";
            }
            $view->registerJs(implode("\n", $js));
        }
    }

    protected function renderBadge($badgeOptions) {
        return ($badgeOptions) ? Html::tag('small', $badgeOptions['text'], ['class'=> $this->getBadgeClass($badgeOptions['type'])]) : '';
    }

    protected function getBadgeClass($type) {
        $class = '';
        switch($type){
            case 'new': $class = 'badge pull-right bg-green'; break;
            case 'notification1':$class = 'badge pull-right bg-red'; break;
            case 'notification2':$class = 'badge pull-right bg-yellow'; break;
        }
        return $class;
    }
}


<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\adminUi\widget;

use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/**
 * Alert renders an alert bootstrap component.
 *
 * For example,
 *
 * ```php
 * echo Alert::widget([
 *     'options' => [
 *         'class' => 'alert-info',
 *     ],
 *     'body' => 'Say hello...',
 * ]);
 * ```
 *
 * The following example will show the content enclosed between the [[begin()]]
 * and [[end()]] calls within the alert box:
 *
 * ```php
 * Alert::begin([
 *     'options' => [
 *         'class' => 'alert-warning',
 *     ],
 * ]);
 *
 * echo 'Say hello...';
 *
 * Alert::end();
 * ```
 *
 * @see http://getbootstrap.com/components/#alerts
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @since 2.0
 */
class Alert extends Widget
{
    use RenderButtonTrait;
    /**
     * @var string the body content in the alert component. Note that anything between
     * the [[begin()]] and [[end()]] calls of the Alert widget will also be treated
     * as the body content, and will be rendered before this.
     */
    public $body;
    /**
     * @var array the options for rendering the close button tag.
     * The close button is displayed in the header of the modal window. Clicking
     * on the button will hide the modal window. If this is null, no close button will be rendered.
     *
     * The following special options are supported:
     *
     * - tag: string, the tag name of the button. Defaults to 'button'.
     * - label: string, the label of the button. Defaults to '×'.
     *
     * The rest of the options will be rendered as the HTML attributes of the button tag.
     * Please refer to the [Alert documentation](http://getbootstrap.com/components/#alerts)
     * for the supported HTML attributes.
     */
    public $closeButton = [];

    public $icon;

    public $fadeeffect = false;

    /**
     * Initializes the widget.
     */
    public function init()
    {
        parent::init();

        $this->initOptions();

        echo Html::beginTag('div', $this->options) . "\n";
        echo $this->renderBodyBegin() . "\n";
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        echo "\n" . $this->renderBodyEnd();
        echo "\n" . Html::endTag('div');

        $this->registerPlugin('alert');
    }

    /**
     * Renders the close button if any before rendering the content.
     * @return string the rendering result
     */
    protected function renderBodyBegin()
    {
        return $this->renderIcon().$this->renderCloseButton();
    }

    /**
     * Renders the alert body (if any).
     * @return string the rendering result
     */
    protected function renderBodyEnd()
    {
        return $this->body . "\n";
    }

    /**
     * Renders the close button.
     * @return string the rendering result
     */
    protected function renderIcon(){
        if ($this->icon !== null) {
            return Html::tag('i', '', ['class' => $this->icon]);
        } else {
            return null;
        }
    }

    /**
     * Initializes the widget options.
     * This method sets the default values for various options.
     */
    protected function initOptions()
    {
        Html::addCssClass($this->options, 'alert');

        if($this->fadeeffect){
            Html::addCssClass($this->options, 'fade');
            Html::addCssClass($this->options, 'in');
        }
        $this->options = array_merge($this->options,['role'=>'alert']);

        if ($this->closeButton !== null) {
            $this->closeButton = array_merge([
                'data-dismiss' => 'alert',
                'aria-hidden' => 'true',
                'class' => 'close',
            ], $this->closeButton);
        }
    }
}


<?php
namespace yii\adminUi\widget;

use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/**
 * Bootstrap box component.
 *
 * @see http://getbootstrap.com/javascript/#dropdowns
 * @author Mithun Mandal <mithun12000@gmail.com>
 * @since 2.0
 */
class SmallBox extends Widget
{
    public $header;

    public $Icon;

    public $caption;

    public $url;

    public $color;
    /**
     * Initializes the widget.
     */
    public function init()
    {
        parent::init();
        $this->initOptions();

        echo Html::beginTag('div', $this->options) . "\n";
        echo Html::beginTag('div', ['class' => 'small-box '.$this->color]) . "\n";
        echo $this->renderHeader() . "\n";
        echo $this->renderBodyBegin() . "\n";
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        if($this->Icon !== NULL){
            echo Html::tag('i', '',['class'=>'ion '.$this->Icon]);
        }
        echo "\n" . $this->renderBodyEnd();
        echo "\n" . $this->renderFooter();
        echo "\n" . Html::endTag('div'); // modal-content
        echo "\n" . Html::endTag('div');
    }

    /**
     * Renders the header HTML markup of the modal
     * @return string the rendering result
     */
    protected function renderHeader()
    {
        if ($this->header !== null) {
            $content = Html::tag('h3', $this->header);

            if($this->caption !== NULL){
                $content .= Html::tag('p', $this->caption);
            }
            return Html::tag('div', $content, ['class' => 'inner']);
        } else {
            return null;
        }
    }

    /**
     * Renders the opening tag of the modal body.
     * @return string the rendering result
     */
    protected function renderBodyBegin()
    {
        return Html::beginTag('div', ['class' => 'icon']);
    }

    /**
     * Renders the closing tag of the modal body.
     * @return string the rendering result
     */
    protected function renderBodyEnd()
    {
        return Html::endTag('div');
    }

    /**
     * Renders the HTML markup for the footer of the modal
     * @return string the rendering result
     */
    protected function renderFooter()
    {
        if ($this->url !== null) {
            return Html::tag('a', 'More info <i class="fa fa-arrow-circle-right"></i>', ['class' => 'small-box-footer','href'=>$this->url]);
        } else {
            return null;
        }

    }

    /**
     * Initializes the widget options.
     * This method sets the default values for various options.
     */
    protected function initOptions()
    {
        if(!$this->color){
            $this->color = 'bg-aqua';
        }
        $this->options = array_merge([
            'class' => 'col-lg-3 col-xs-6',
        ], $this->options);
        //Html::addCssClass($this->options, 'modal');
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: String.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Helper;

use \ArrayAccess;
use \Iterator;
use \Countable;
use TeamSpeak3\TeamSpeak3;
use TeamSpeak3\Ts3Exception;

/**
 * @class String
 * @brief Helper class for string handling.
 */
class StringHelper implements ArrayAccess, Iterator, Countable
{
    /**
     * Stores the original string.
     *
     * @var string
     */
    protected $string;

    /**
     * @ignore
     */
    protected $position = 0;

    /**
     * The String constructor.
     *
     * @param  string $string
     */
    public function __construct($string)
    {
        $this->string = strval($string);
    }

    /**
     * Returns a String object for thegiven string.
     *
     * @param  string $string
     * @return StringHelper
     */
    public static function factory($string)
    {
        return new self($string);
    }

    /**
     * Replaces every occurrence of the string $search with the string $replace.
     *
     * @param  string $search
     * @param  string $replace
     * @param  boolean $caseSensitivity
     * @return StringHelper
     */
    public function replace($search, $replace, $caseSensitivity = true)
    {
        if ($caseSensitivity) {
            $this->string = str_replace($search, $replace, $this->string);
        } else {
            $this->string = str_ireplace($search, $replace, $this->string);
        }

        return $this;
    }

    /**
     * This function replaces indexed or associative signs with given values.
     *
     * @param  array $args
     * @param  string $char
     * @return StringHelper
     */
    public function arg(array $args, $char = "%")
    {
        $args = array_reverse($args, true);

        foreach ($args as $key => $val) {
            $args[$char . $key] = $val;
            unset($args[$key]);
        }

        $this->string = strtr($this->string, $args);

        return $this;
    }

    /**
     * Returns true if the string starts with $pattern.
     *
     * @param  string $pattern
     * @return boolean
     */
    public function startsWith($pattern)
    {
        return (substr($this->string, 0, strlen($pattern)) == $pattern) ? true : false;
    }

    /**
     * Returns true if the string ends with $pattern.
     *
     * @param  string $pattern
     * @return boolean
     */
    public function endsWith($pattern)
    {
        return (substr($this->string, strlen($pattern) * -1) == $pattern) ? true : false;
    }

    /**
     * Returns the position of the first occurrence of a char in a string.
     *
     * @param  string $needle
     * @return integer
     */
    public function findFirst($needle)
    {
        return strpos($this->string, $needle);
    }

    /**
     * Returns the position of the last occurrence of a char in a string.
     *
     * @param  string $needle
     * @return integer
     */
    public function findLast($needle)
    {
        return strrpos($this->string, $needle);
    }

    /**
     * Returns the lowercased string.
     *
     * @return StringHelper
     */
    public function toLower()
    {
        return new self(strtolower($this->string));
    }

    /**
     * Returns the uppercased string.
     *
     * @return StringHelper
     */
    public function toUpper()
    {
        return new self(strtoupper($this->string));
    }

    /**
     * Returns true if the string contains $pattern.
     *
     * @param  string $pattern
     * @param bool $regexp
     * @return bool
     */
    public function contains($pattern, $regexp = false)
    {
        if (empty($pattern)) {
            return true;
        }

        if ($regexp) {
            return (preg_match("/" . $pattern . "/i", $this->string)) ? true : false;
        } else {
            return (stristr($this->string, $pattern) !== false) ? true : false;
        }
    }

    /**
     * Returns part of a string.
     *
     * @param  integer $start
     * @param  integer $length
     * @return StringHelper
     */
    public function substr($start, $length = null)
    {
        $string = ($length !== null) ? substr($this->string, $start, $length) : substr($this->string, $start);

        return new self($string);
    }

    /**
     * Splits the string into substrings wherever $separator occurs.
     *
     * @param  string $separator
     * @param  integer $limit
     * @return array
     */
    public function split($separator, $limit = 0)
    {
        $parts = explode($separator, $this->string, ($limit) ? intval($limit) : $this->count());

        foreach ($parts as $key => $val) {
            $parts[$key] = new self($val);
        }

        return $parts;
    }

    /**
     * Appends $part to the string.
     *
     * @param  string $part
     * @return StringHelper
     */
    public function append($part)
    {
        $this->string = $this->string . strval($part);

        return $this;
    }

    /**
     * Prepends $part to the string.
     *
     * @param  string $part
     * @return StringHelper
     */
    public function prepend($part)
    {
        $this->string = strval($part) . $this->string;

        return $this;
    }

    /**
     * Returns a section of the string.
     *
     * @param  string $separator
     * @param  integer $first
     * @param  integer $last
     * @return StringHelper
     */
    public function section($separator, $first = 0, $last = 0)
    {
        $sections = explode($separator, $this->string);

        $total = count($sections);
        $first = intval($first);
        $last = intval($last);

        if ($first > $total) {
            return null;
        }
        if ($first > $last) {
            $last = $first;
        }

        for ($i = 0; $i < $total; $i++) {
            if ($i < $first || $i > $last) {
                unset($sections[$i]);
            }
        }

        $string = implode($separator, $sections);

        return new self($string);
    }

    /**
     * Sets the size of the string to $size characters.
     *
     * @param  integer $size
     * @param  string $char
     * @return StringHelper
     */
    public function resize($size, $char = "\0")
    {
        $chars = ($size - $this->count());

        if ($chars < 0) {
            $this->string = substr($this->string, 0, $chars);
        } elseif ($chars > 0) {
            $this->string = str_pad($this->string, $size, strval($char));
        }

        return $this;
    }

    /**
     * Strips whitespaces (or other characters) from the beginning and end of the string.
     *
     * @return StringHelper
     */
    public function trim()
    {
        $this->string = trim($this->string);

        return $this;
    }

    /**
     * Escapes a string using the TeamSpeak 3 escape patterns.
     *
     * @return StringHelper
     */
    public function escape()
    {
        foreach (TeamSpeak3::getEscapePatterns() as $search => $replace) {
            $this->string = str_replace($search, $replace, $this->string);
        }

        return $this;
    }

    /**
     * Unescapes a string using the TeamSpeak 3 escape patterns.
     *
     * @return StringHelper
     */
    public function unescape()
    {
        $this->string = strtr($this->string, array_flip(TeamSpeak3::getEscapePatterns()));

        return $this;
    }

    /**
     * Removes any non alphanumeric characters from the string.
     *
     * @return StringHelper
     */
    public function filterAlnum()
    {
        $this->string = preg_replace("/[^[:alnum:]]/", "", $this->string);

        return $this;
    }

    /**
     * Removes any non alphabetic characters from the string.
     *
     * @return StringHelper
     */
    public function filterAlpha()
    {
        $this->string = preg_replace("/[^[:alpha:]]/", "", $this->string);

        return $this;
    }

    /**
     * Removes any non numeric characters from the string.
     *
     * @return StringHelper
     */
    public function filterDigits()
    {
        $this->string = preg_replace("/[^[:digit:]]/", "", $this->string);

        return $this;
    }

    /**
     * Returns TRUE if the string is a numeric value.
     *
     * @return boolean
     */
    public function isInt()
    {
        return (is_numeric($this->string) && !$this->contains(".")) ? true : false;
    }

    /**
     * Returns the integer value of the string.
     *
     * @return float
     * @return integer
     */
    public function toInt()
    {
        if ($this->string == pow(2, 63) || $this->string == pow(2, 64)) {
            return -1;
        }

        return ($this->string > pow(2, 31)) ? floatval($this->string) : intval($this->string);
    }

    /**
     * Calculates and returns the crc32 polynomial of the string.
     *
     * @return string
     */
    public function toCrc32()
    {
        return crc32($this->string);
    }

    /**
     * Calculates and returns the md5 checksum of the string.
     *
     * @return string
     */
    public function toMd5()
    {
        return md5($this->string);
    }

    /**
     * Calculates and returns the sha1 checksum of the string.
     *
     * @return string
     */
    public function toSha1()
    {
        return sha1($this->string);
    }

    /**
     * Returns TRUE if the string is UTF-8 encoded. This method searches for non-ascii multibyte
     * sequences in the UTF-8 range.
     *
     * @return boolean
     */
    public function isUtf8()
    {
        $pattern = array();

        $pattern[] = "[\xC2-\xDF][\x80-\xBF]"; // non-overlong 2-byte
        $pattern[] = "\xE0[\xA0-\xBF][\x80-\xBF]"; // excluding overlongs
        $pattern[] = "[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}"; // straight 3-byte
        $pattern[] = "\xED[\x80-\x9F][\x80-\xBF]"; // excluding surrogates
        $pattern[] = "\xF0[\x90-\xBF][\x80-\xBF]{2}"; // planes 1-3
        $pattern[] = "[\xF1-\xF3][\x80-\xBF]{3}"; // planes 4-15
        $pattern[] = "\xF4[\x80-\x8F][\x80-\xBF]{2}"; // plane 16

        return preg_match("%(?:" . implode("|", $pattern) . ")+%xs", $this->string);
    }

    /**
     * Converts the string to UTF-8.
     *
     * @return StringHelper
     */
    public function toUtf8()
    {
        if (!$this->isUtf8()) {
            $this->string = utf8_encode($this->string);
        }

        return $this;
    }

    /**
     * Encodes the string with MIME base64 and returns the result.
     *
     * @return string
     */
    public function toBase64()
    {
        return base64_encode($this->string);
    }

    /**
     * Decodes the string with MIME base64 and returns the result as an String
     *
     * @param  string
     * @return StringHelper
     */
    public static function fromBase64($base64)
    {
        return new self(base64_decode($base64));
    }

    /**
     * Returns the hexadecimal value of the string.
     *
     * @return string
     */
    public function toHex()
    {
        $hex = "";

        foreach ($this as $char) {
            $hex .= $char->toHex();
        }

        return $hex;
    }

    /**
     * Returns the String based on a given hex value.
     *
     * @param  string
     * @throws Ts3Exception
     * @return StringHelper
     */
    public static function fromHex($hex)
    {
        $string = "";

        if (strlen($hex) % 2 == 1) {
            throw new Ts3Exception("given parameter '" . $hex . "' is not a valid hexadecimal number");
        }

        foreach (str_split($hex, 2) as $chunk) {
            $string .= chr(hexdec($chunk));
        }

        return new self($string);
    }

    /**
     * Returns the string transliterated from UTF-8 to Latin.
     *
     * @return StringHelper
     */
    public function transliterate()
    {
        $utf8_accents = array(
            "à" => "a",
            "ô" => "o",
            "�?" => "d",
            "ḟ" => "f",
            "ë" => "e",
            "š" => "s",
            "ơ" => "o",
            "ß" => "ss",
            "ă" => "a",
            "ř" => "r",
            "ț" => "t",
            "ň" => "n",
            "�?" => "a",
            "ķ" => "k",
            "�?" => "s",
            "ỳ" => "y",
            "ņ" => "n",
            "ĺ" => "l",
            "ħ" => "h",
            "ṗ" => "p",
            "ó" => "o",
            "ú" => "u",
            "ě" => "e",
            "é" => "e",
            "ç" => "c",
            "�?" => "w",
            "ċ" => "c",
            "õ" => "o",
            "ṡ" => "s",
            "ø" => "o",
            "ģ" => "g",
            "ŧ" => "t",
            "ș" => "s",
            "ė" => "e",
            "ĉ" => "c",
            "ś" => "s",
            "î" => "i",
            "ű" => "u",
            "ć" => "c",
            "ę" => "e",
            "ŵ" => "w",
            "ṫ" => "t",
            "ū" => "u",
            "�?" => "c",
            "ö" => "oe",
            "è" => "e",
            "ŷ" => "y",
            "ą" => "a",
            "ł" => "l",
            "ų" => "u",
            "ů" => "u",
            "ş" => "s",
            "ğ" => "g",
            "ļ" => "l",
            "ƒ" => "f",
            "ž" => "z",
            "ẃ" => "w",
            "ḃ" => "b",
            "å" => "a",
            "ì" => "i",
            "ï" => "i",
            "ḋ" => "d",
            "ť" => "t",
            "ŗ" => "r",
            "ä" => "ae",
            "í" => "i",
            "ŕ" => "r",
            "ê" => "e",
            "ü" => "ue",
            "ò" => "o",
            "ē" => "e",
            "ñ" => "n",
            "ń" => "n",
            "ĥ" => "h",
            "�?" => "g",
            "đ" => "d",
            "ĵ" => "j",
            "ÿ" => "y",
            "ũ" => "u",
            "ŭ" => "u",
            "ư" => "u",
            "ţ" => "t",
            "ý" => "y",
            "ő" => "o",
            "â" => "a",
            "ľ" => "l",
            "ẅ" => "w",
            "ż" => "z",
            "ī" => "i",
            "ã" => "a",
            "ġ" => "g",
            "�?" => "m",
            "�?" => "o",
            "ĩ" => "i",
            "ù" => "u",
            "į" => "i",
            "ź" => "z",
            "á" => "a",
            "û" => "u",
            "þ" => "th",
            "ð" => "dh",
            "æ" => "ae",
            "µ" => "u",
            "ĕ" => "e",
            "œ" => "oe",
            "À" => "A",
            "Ô" => "O",
            "Ď" => "D",
            "Ḟ" => "F",
            "Ë" => "E",
            "Š" => "S",
            "Ơ" => "O",
            "Ă" => "A",
            "Ř" => "R",
            "Ț" => "T",
            "Ň" => "N",
            "Ā" => "A",
            "Ķ" => "K",
            "Ŝ" => "S",
            "Ỳ" => "Y",
            "Ņ" => "N",
            "Ĺ" => "L",
            "Ħ" => "H",
            "Ṗ" => "P",
            "Ó" => "O",
            "Ú" => "U",
            "Ě" => "E",
            "É" => "E",
            "Ç" => "C",
            "Ẁ" => "W",
            "Ċ" => "C",
            "Õ" => "O",
            "Ṡ" => "S",
            "Ø" => "O",
            "Ģ" => "G",
            "Ŧ" => "T",
            "Ș" => "S",
            "Ė" => "E",
            "Ĉ" => "C",
            "Ś" => "S",
            "Î" => "I",
            "Ű" => "U",
            "Ć" => "C",
            "Ę" => "E",
            "Ŵ" => "W",
            "Ṫ" => "T",
            "Ū" => "U",
            "Č" => "C",
            "Ö" => "Oe",
            "È" => "E",
            "Ŷ" => "Y",
            "Ą" => "A",
            "�?" => "L",
            "Ų" => "U",
            "Ů" => "U",
            "Ş" => "S",
            "Ğ" => "G",
            "Ļ" => "L",
            "Ƒ" => "F",
            "Ž" => "Z",
            "Ẃ" => "W",
            "Ḃ" => "B",
            "Å" => "A",
            "Ì" => "I",
            "�?" => "I",
            "Ḋ" => "D",
            "Ť" => "T",
            "Ŗ" => "R",
            "Ä" => "Ae",
            "�?" => "I",
            "Ŕ" => "R",
            "Ê" => "E",
            "Ü" => "Ue",
            "Ò" => "O",
            "Ē" => "E",
            "Ñ" => "N",
            "Ń" => "N",
            "Ĥ" => "H",
            "Ĝ" => "G",
            "�?" => "D",
            "Ĵ" => "J",
            "Ÿ" => "Y",
            "Ũ" => "U",
            "Ŭ" => "U",
            "Ư" => "U",
            "Ţ" => "T",
            "�?" => "Y",
            "�?" => "O",
            "Â" => "A",
            "Ľ" => "L",
            "Ẅ" => "W",
            "Ż" => "Z",
            "Ī" => "I",
            "Ã" => "A",
            "Ġ" => "G",
            "Ṁ" => "M",
            "Ō" => "O",
            "Ĩ" => "I",
            "Ù" => "U",
            "Į" => "I",
            "Ź" => "Z",
            "�?" => "A",
            "Û" => "U",
            "Þ" => "Th",
            "�?" => "Dh",
            "Æ" => "Ae",
            "Ĕ" => "E",
            "Œ" => "Oe",
        );

        return new self($this->toUtf8()->replace(array_keys($utf8_accents), array_values($utf8_accents)));
    }

    /**
     * Processes the string and replaces all accented UTF-8 characters by unaccented ASCII-7 "equivalents",
     * whitespaces are replaced by a pre-defined spacer and the string is lowercase.
     *
     * @param  string $spacer
     * @return StringHelper
     */
    public function uriSafe($spacer = "-")
    {
        $this->string = str_replace($spacer, " ", $this->string);
        $this->string = $this->transliterate();
        $this->string = preg_replace("/(\s|[^A-Za-z0-9\-])+/", $spacer, trim(strtolower($this->string)));
        $this->string = trim($this->string, $spacer);

        return new self($this->string);
    }

    /**
     * Replaces space characters with percent encoded strings.
     *
     * @return string
     */
    public function spaceToPercent()
    {
        return str_replace(" ", "%20", $this->string);
    }

    /**
     * Returns the string as a standard string
     *
     * @return string
     */
    public function toString()
    {
        return $this->string;
    }

    /**
     * Magical function that allows you to call PHP's built-in string functions on the String object.
     *
     * @param  string $function
     * @param  array $args
     * @throws Ts3Exception
     * @return StringHelper
     */
    public function __call($function, $args)
    {
        if (!function_exists($function)) {
            throw new Ts3Exception("cannot call undefined function '" . $function . "' on this object");
        }

        if (count($args)) {
            if (($key = array_search($this, $args, true)) !== false) {
                $args[$key] = $this->string;
            } else {
                throw new Ts3Exception(
                    "cannot call undefined function '" . $function . "' without the " . __CLASS__ . " object parameter"
                );
            }

            $return = call_user_func_array($function, $args);
        } else {
            $return = call_user_func($function, $this->string);
        }

        if (is_string($return)) {
            $this->string = $return;
        } else {
            return $return;
        }

        return $this;
    }

    /**
     * Returns the character as a standard string.
     *
     * @return string
     */
    public function __toString()
    {
        return (string)$this->string;
    }

    /**
     * @ignore
     */
    public function count()
    {
        return strlen($this->string);
    }

    /**
     * @ignore
     */
    public function rewind()
    {
        $this->position = 0;
    }

    /**
     * @ignore
     */
    public function valid()
    {
        return $this->position < $this->count();
    }

    /**
     * @ignore
     */
    public function key()
    {
        return $this->position;
    }

    /**
     * @ignore
     */
    public function current()
    {
        return new Char($this->string{$this->position});
    }

    /**
     * @ignore
     */
    public function next()
    {
        $this->position++;
    }

    /**
     * @ignore
     */
    public function offsetExists($offset)
    {
        return ($offset < strlen($this->string)) ? true : false;
    }

    /**
     * @ignore
     */
    public function offsetGet($offset)
    {
        return ($this->offsetExists($offset)) ? new Char($this->string{$offset}) : null;
    }

    /**
     * @ignore
     */
    public function offsetSet($offset, $value)
    {
        if (!$this->offsetExists($offset)) {
            return;
        }

        $this->string{$offset} = strval($value);
    }

    /**
     * @ignore
     */
    public function offsetUnset($offset)
    {
        if (!$this->offsetExists($offset)) {
            return;
        }

        $this->string = substr_replace($this->string, "", $offset, 1);
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: Ts3Exception.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3;

use TeamSpeak3\Helper\Signal;
use TeamSpeak3\Helper\StringHelper;

/**
 * @class Ts3Exception
 * @brief Enhanced exception class for TeamSpeak3 objects.
 */
class Ts3Exception extends \Exception
{
    /**
     * Stores custom error messages.
     *
     * @var array
     */
    protected static $messages = array();

    /**
     * The Ts3Exception constructor.
     *
     * @param  string $mesg
     * @param  integer $code
     * @return Ts3Exception
     */
    public function __construct($mesg, $code = 0x00)
    {
        parent::__construct($mesg, $code);

        if (array_key_exists((int)$code, self::$messages)) {
            $this->message = $this->prepareCustomMessage(self::$messages[intval($code)]);
        }

        Signal::getInstance()->emit("errorException", $this);
    }

    /**
     * Prepares a custom error message by replacing pre-defined signs with given values.
     *
     * @param \Teamspeak3\Helper\StringHelper $mesg
     * @return \Teamspeak3\Helper\StringHelper
     */
    protected function prepareCustomMessage(StringHelper $mesg)
    {
        $args = array(
            "code" => $this->getCode(),
            "mesg" => $this->getMessage(),
            "line" => $this->getLine(),
            "file" => $this->getFile(),
        );

        return $mesg->arg($args)->toString();
    }

    /**
     * Registers a custom error message to $code.
     *
     * @param  integer $code
     * @param  string $mesg
     * @throws Ts3Exception
     * @return void
     */
    public static function registerCustomMessage($code, $mesg)
    {
        if (array_key_exists((int)$code, self::$messages)) {
            throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is already registered");
        }

        if (!is_string($mesg)) {
            throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " must be a string");
        }

        self::$messages[(int)$code] = new StringHelper($mesg);
    }

    /**
     * Unregisters a custom error message from $code.
     *
     * @param  integer $code
     * @throws Ts3Exception
     * @return void
     */
    public static function unregisterCustomMessage($code)
    {
        if (!array_key_exists((int)$code, self::$messages)) {
            throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is not registered");
        }

        unset(self::$messages[intval($code)]);
    }

    /**
     * Returns the class from which the exception was thrown.
     *
     * @return string
     */
    public function getSender()
    {
        $trace = $this->getTrace();

        return (isset($trace[0]["class"])) ? $trace[0]["class"] : "{main}";
    }
}


<?php

/**
 * @file
 * TeamSpeak 3 PHP Framework
 *
 * $Id: Client.php 10/11/2013 11:35:21 scp@orilla $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TeamSpeak3
 * @version   1.1.23
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
 */

namespace TeamSpeak3\Node;

use TeamSpeak3\Helper\StringHelper;
use TeamSpeak3\TeamSpeak3;

/**
 * @class Client
 * @brief Class describing a TeamSpeak 3 client and all it's parameters.
 */
class Client extends AbstractNode
{
    /**
     * The Client constructor.
     *
     * @param  Server $server
     * @param  array $info
     * @param  string $index
     * @throws TeamSpeak3_Adapter_ServerQuery_Exception
     * @return Client
     */
    public function __construct(Server $server, array $info, $index = "clid")
    {
        $this->parent = $server;
        $this->nodeInfo = $info;

        if (!array_key_exists($index, $this->nodeInfo)) {
            throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
        }

        $this->nodeId = $this->nodeInfo[$index];
    }

    /**
     * Changes the clients properties using given properties.
     *
     * @param  array $properties
     * @return void
     */
    public function modify(array $properties)
    {
        $properties["clid"] = $this->getId();

        $this->execute("clientedit", $properties);
        $this->resetNodeInfo();
    }

    /**
     * Changes the clients properties using given properties.
     *
     * @param  array $properties
     * @return void
     */
    public function modifyDb(array $properties)
    {
        return $this->getParent()->clientModifyDb($this["client_database_id"], $properties);
    }

    /**
     * Deletes the clients properties from the database.
     *
     * @return void
     */
    public function deleteDb()
    {
        return $this->getParent()->clientDeleteDb($this["client_database_id"]);
    }

    /**
     * Returns a list of properties from the database for the client.
     *
     * @return array
     */
    public function infoDb()
    {
        return $this->getParent()->clientInfoDb($this["client_database_id"]);
    }

    /**
     * Sends a text message to the client.
     *
     * @param  string $msg
     * @return void
     */
    public function message($msg)
    {
        $this->execute(
            "sendtextmessage",
            array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)
        );
    }

    /**
     * Moves the client to another channel.
     *
     * @param  integer $cid
     * @param  string $cpw
     * @return void
     */
    public function move($cid, $cpw = null)
    {
        return $this->getParent()->clientMove($this->getId(), $cid, $cpw);
    }

    /**
     * Kicks the client from his currently joined channel or from the server.
     *
     * @param  integer $reasonid
     * @param  string $reasonmsg
     * @return void
     */
    public function kick($reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
    {
        return $this->getParent()->clientKick($this->getId(), $reasonid, $reasonmsg);
    }

    /**
     * Sends a poke message to the client.
     *
     * @param  string $msg
     * @return void
     */
    public function poke($msg)
    {
        return $this->getParent()->clientPoke($this->getId(), $msg);
    }

    /**
     * Bans the client from the server. Please note that this will create two separate
     * ban rules for the targeted clients IP address and his unique identifier.
     *
     * @param  integer $timeseconds
     * @param  string $reason
     * @return array
     */
    public function ban($timeseconds = null, $reason = null)
    {
        return $this->getParent()->clientBan($this->getId(), $timeseconds, $reason);
    }

    /**
     * Returns a list of custom properties for the client.
     *
     * @return array
     */
    public function customInfo()
    {
        return $this->getParent()->customInfo($this["client_database_id"]);
    }

    /**
     * Returns an array containing the permission overview of the client.
     *
     * @param  integer $cid
     * @return array
     */
    public function permOverview($cid)
    {
        return $this->execute(
            "permoverview",
            array("cldbid" => $this["client_database_id"], "cid" => $cid, "permid" => 0)
        )->toArray();
    }

    /**
     * Returns a list of permissions defined for the client.
     *
     * @param  boolean $permsid
     * @return array
     */
    public function permList($permsid = false)
    {
        return $this->getParent()->clientPermList($this["client_database_id"], $permsid);
    }

    /**
     * Adds a set of specified permissions to the client. Multiple permissions can be added by providing
     * the three parameters of each permission.
     *
     * @param  integer $permid
     * @param  integer $permvalue
     * @param  integer $permskip
     * @return void
     */
    public function permAssign($permid, $permvalue, $permskip = false)
    {
        return $this->getParent()->clientPermAssign($this["client_database_id"], $permid, $permvalue, $permskip);
    }

    /**
     * Alias for permAssign().
     *
     * @deprecated
     */
    public function permAssignByName($permname, $permvalue, $permskip = false)
    {
        return $this->permAssign($permname, $permvalue, $permskip);
    }

    /**
     * Removes a set of specified permissions from a client. Multiple permissions can be removed at once.
     *
     * @param integer $permid
     * @return void
     */
    public function permRemove($permid)
    {
        return $this->getParent()->clientPermRemove($this["client_database_id"], $permid);
    }

    /**
     * Alias for permRemove().
     *
     * @deprecated
     */
    public function permRemoveByName($permname)
    {
        return $this->permRemove($permname);
    }

    /**
     * Sets the channel group of a client to the ID specified.
     *
     * @param  integer $cid
     * @param  integer $cgid
     * @return void
     */
    public function setChannelGroup($cid, $cgid)
    {
        return $this->getParent()->clientSetChannelGroup($this["client_database_id"], $cid, $cgid);
    }

    /**
     * Adds the client to the server group specified with $sgid.
     *
     * @param  integer $sgid
     * @return void
     */
    public function addServerGroup($sgid)
    {
        return $this->getParent()->serverGroupClientAdd($sgid, $this["client_database_id"]);
    }

    /**
     * Removes the client from the server group specified with $sgid.
     *
     * @param  integer $sgid
     * @return void
     */
    public function remServerGroup($sgid)
    {
        return $this->getParent()->serverGroupClientDel($sgid, $this["client_database_id"]);
    }

    /**
     * Returns the possible name of the clients avatar.
     *
     * @return StringHelper
     */
    public function avatarGetName()
    {
        return new StringHelper("/avatar_" . $this["client_base64HashClientUID"]);
    }

    /**
     * Downloads and returns the clients avatar file content.
     *
     * @return StringHelper
     */
    public function avatarDownload()
    {
        if ($this["client_flag_avatar"] == 0) {
            return;
        }

        $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName());
        $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);

        return $transfer->download($download["ftkey"], $download["size"]);
    }

    /**
     * Returns a list of client connections using the same identity as this client.
     *
     * @return array
     */
    public function getClones()
    {
        return $this->execute("clientgetids", array("cluid" => $this["client_unique_identifier"]))->toAssocArray(
            "clid"
        );
    }

    /**
     * Returns the revision/build number from the clients version string.
     *
     * @return integer
     */
    public function getRev()
    {
        return $this["client_type"] ? null : $this["client_version"]->section("[", 1)->filterDigits();
    }

    /**
     * Returns all server and channel groups the client is currently residing in.
     *
     * @return array
     */
    public function memberOf()
    {
        $groups = array($this->getParent()->channelGroupGetById($this["client_channel_group_id"]));

        foreach (explode(",", $this["client_servergroups"]) as $sgid) {
            $groups[] = $this->getParent()->serverGroupGetById($sgid);
        }

        return $groups;
    }

    /**
     * Downloads and returns the clients icon file content.
     *
     * @return StringHelper
     */
    public function iconDownload()
    {
        if ($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) {
            return;
        }

        $download = $this->getParent()->transferInitDownload(
            rand(0x0000, 0xFFFF),
            0,
            $this->iconGetName("client_icon_id")
        );
        $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);

        return $transfer->download($download["ftkey"], $download["size"]);
    }

    /**
     * Sends a plugin command to the client.
     *
     * @param  string $plugin
     * @param  string $data
     * @return void
     */
    public function sendPluginCmd($plugin, $data)
    {
        $this->execute(
            "plugincmd",
            array(
                "name" => $plugin,
                "data" => $data,
                "targetmode" => TeamSpeak3::PLUGINCMD_CLIENT,
                "target" => $this->getId()
            )
        );
    }

    /**
     * @ignore
     */
    protected function fetchNodeInfo()
    {
        if ($this["client_type"] == 1) {
            return;
        }

        $this->nodeInfo = array_merge(
            $this->nodeInfo,
            $this->execute("clientinfo", array("clid" => $this->getId()))->toList()
        );
    }

    /**
     * Returns a unique identifier for the node which can be used as a HTML property.
     *
     * @return string
     */
    public function getUniqueId()
    {
        return $this->getParent()->getUniqueId() . "_cl" . $this->getId();
    }

    /**
     * Returns the name of a possible icon to display the node object.
     *
     * @return string
     */
    public function getIcon()
    {
        if ($this["client_type"]) {
            return "client_query";
        } elseif ($this["client_away"]) {
            return "client_away";
        } elseif (!$this["client_output_hardware"]) {
            return "client_snd_disabled";
        } elseif ($this["client_output_muted"]) {
            return "client_snd_muted";
        } elseif (!$this["client_input_hardware"]) {
            return "client_mic_disabled";
        } elseif ($this["client_input_muted"]) {
            return "client_mic_muted";
        } elseif ($this["client_is_channel_commander"]) {
            return $this["client_flag_talking"] ? "client_cc_talk" : "client_cc_idle";
        } else {
            return $this["client_flag_talking"] ? "client_talk" : "client_idle";
        }
    }

    /**
     * Returns a symbol representing the node.
     *
     * @return string
     */
    public function getSymbol()
    {
        return "@";
    }

    /**
     * Returns a string representation of this node.
     *
     * @return string
     */
    public function __toString()
    {
        return (string)$this["client_nickname"];
    }
}