コード例 #1
0
ファイル: bot.php プロジェクト: briancline/ircplanet
 function noticef($target, $format)
 {
     $args = func_get_args();
     $target = array_shift($args);
     // Remove target
     $format = array_shift($args);
     // Remove format
     if (is_object($target) && isUser($target)) {
         $target = $target->getNumeric();
     }
     $notice_text = irc_vsprintf($format, $args);
     $this->net->sendf(FMT_NOTICE, $this->numeric, $target, $notice_text);
 }
コード例 #2
0
/**
 * irc_sprintf provides a cleaner way of sending services-specific data structures
 * to sprintf without having to repeatedly provide long member function calls as 
 * sprintf arguments. Since we almost always use the same member functions in
 * most scenarios, irc_sprintf does a lot of legwork and makes for cleaner code.
 *
 * The custom conversion specifiers that can be used with irc_sprintf follow:
 * 
 *  %A    A space-delimited string representing all of an array's elements.
 *        Designed for string or numeric arrays only.
 *  
 *  %H    Human-readable name of the referenced object.
 *        For channels:  channel name.
 *        For servers:   full server name.
 *        For users:     nick name.
 *        For bots:      nick name.
 *        For glines:    the full mask of the gline.
 *  
 *  %C    Same as %H. Pneumonically represents channel names; provided as an extra
 *        flag only for readability in longer format strings.
 *  
 *  %N    The ircu numeric of the referenced object.
 *        For servers:   two-character server numeric (ex., Sc).
 *        For users:     five-character server+user numeric (ex., ScAAA).
 *        For bots:      five-character server+user numeric (ex., ScAAA).
 *  
 *  %U    The account name of the referenced object.
 *        For users:     user's logged-in account name, if any.
 *        For accounts:  account name.
 *  
 * Examples:
 *    sprintf('%s', $user_obj->getNick());    // Nick name
 *    irc_sprintf('%H', $user_obj);            // Nick name
 *    irc_sprintf('[%'#-13H]', $user_obj);     // Nick name, left-aligned in brackets
 *                                                and padded with hash symbols
 *  
 * The following are totally equivalent; the latter saves much space and provides
 * visual feedback as to what each argument corresponds to (numeric, channel, etc):
 *    
 *    sprintf('%s M %s +o %s %ld', $user_obj->getNumeric(), $chan_obj->getName, 
 *            $user2_obj->getNumeric(), time());
 *    
 *    irc_sprintf('%N M %C +o %N %ld', $user_obj, $chan_obj, $user2_obj, time());
 * 
 */
function irc_sprintf($format)
{
    $args = func_get_args();
    // Get array of all function arguments for vsprintf
    array_shift($args);
    // Pop the format argument from the top
    return irc_vsprintf($format, $args);
}