コード例 #1
0
/**
 * irc_vsprintf: Identical to vsprintf, except extended to allow the IRC-specific
 * conversion specifiers documented with irc_sprintf.
 */
function irc_vsprintf($format, $args)
{
    $std_types = 'bcdeufFosxX';
    $custom_types = 'ACHNU';
    $len = strlen($format);
    $arg_index = -1;
    $pct_count = 0;
    for ($i = 0; $i < $len - 1; $i++) {
        $char = $format[$i];
        $next = $format[$i + 1];
        if ($char == '%') {
            $pct_count++;
        } else {
            $pct_count = 0;
        }
        /**
         * Skip this character if we don't have the start of a spec yet, or
         * if we do and the following character is a '%', indicating that
         * vsprintf will simply substitute a percent sign.
         */
        if ($pct_count != 1 || $next == '%') {
            continue;
        }
        // Found a spec; hold its place
        $spec_start = $i;
        $spec_end = $i + 1;
        $type = '';
        /**
         * Loop through the characters immediately following so that we can
         * attempt to find the type of spec this is. The formatting flags will
         * be preserved, so we'll ignore them.
         */
        for ($j = $i + 1; $j < $len; $j++) {
            $tmp_char = $format[$j];
            $is_std_type = false !== strpos($std_types, $tmp_char);
            $is_cust_type = false !== strpos($custom_types, $tmp_char);
            if ($is_std_type || $is_cust_type) {
                // Found a valid standard or custom flag, mark its place and stop
                $type = $tmp_char;
                $arg_index++;
                $spec_end = $j;
                break;
            }
        }
        // If we found a custom type in this spec, process it accordingly
        if ($is_cust_type) {
            $arg_obj = $args[$arg_index];
            $cust_text = '';
            switch ($type) {
                /**
                 * %A: Flat array to string conversion
                 */
                case 'A':
                    $cust_text = implode(' ', $arg_obj);
                    break;
                    /**
                     * %H: Human-readable name of given object
                     */
                /**
                 * %H: Human-readable name of given object
                 */
                case 'C':
                case 'H':
                    if (isUser($arg_obj)) {
                        $cust_text = $arg_obj->getNick();
                    } elseif (isChannel($arg_obj) || isServer($arg_obj)) {
                        $cust_text = $arg_obj->getName();
                    } elseif (isGline($arg_obj)) {
                        $cust_text = $arg_obj->getMask();
                    }
                    break;
                    /**
                     * %N: ircu P10 numeric of given object
                     */
                /**
                 * %N: ircu P10 numeric of given object
                 */
                case 'N':
                    if (isUser($arg_obj) || isServer($arg_obj)) {
                        $cust_text = $arg_obj->getNumeric();
                    }
                    break;
                    /**
                     * %U: Account name of user or account object
                     */
                /**
                 * %U: Account name of user or account object
                 */
                case 'U':
                    if (isUser($arg_obj)) {
                        $cust_text = $arg_obj->getAccountName();
                    } elseif (isAccount($arg_obj)) {
                        $cust_text = $arg_obj->getName();
                    }
                    break;
                    /**
                     * I'm sorry, Dave, I'm afraid I can't do that.
                     * Will pass this unknown spec to vsprintf as-is.
                     */
                /**
                 * I'm sorry, Dave, I'm afraid I can't do that.
                 * Will pass this unknown spec to vsprintf as-is.
                 */
                default:
                    continue;
            }
            /**
             * Change the custom flag to an 's' (string) and replace the argument
             * with whatever string we determined was most appropriate for it.
             */
            $format[$spec_end] = 's';
            $args[$arg_index] = $cust_text;
            /**
             * No need to look at this entire spec anymore, so advance to the next
             * char after the end of the spec.
             */
            $i = $spec_end + 1;
        }
    }
    // vsprintf takes care of the standard flags.
    return vsprintf($format, $args);
}
コード例 #2
0
 function enforceGline($gline)
 {
     if (!isGline($gline) && !($gline = $this->getGline($gline))) {
         return false;
     }
     $this->sendf(FMT_GLINE_ADD, SERVER_NUM, $gline->getMask(), $gline->getDuration(), $gline->getLastmodTs(), $gline->getReason());
     return true;
 }
コード例 #3
0
ファイル: service.php プロジェクト: briancline/ircplanet
 function enforceGline($gline)
 {
     if (!isGline($gline) && !($gline = $this->getGline($gline))) {
         return false;
     }
     $format = FMT_GLINE_ACTIVE;
     if (!$gline->isActive()) {
         $format = FMT_GLINE_INACTIVE;
     }
     $this->sendf($format, SERVER_NUM, $gline->getMask(), $gline->getDuration(), $gline->getLastMod(), $gline->getLifetime(), $gline->getReason());
     return true;
 }