示例#1
0
function Q_after_Q_tool_render($params, &$result)
{
    $info = $params['info'];
    $extra = $params['extra'];
    if (!is_array($extra)) {
        $extra = array();
    }
    $id_prefix = Q_Html::getIdPrefix();
    $tool_ids = Q_Html::getToolIds();
    $tag = Q::ifset($extra, 'tag', 'div');
    if (empty($tag)) {
        Q_Html::popIdPrefix();
        return;
    }
    $classes = '';
    $data_options = '';
    $count = count($info);
    foreach ($info as $name => $opt) {
        $classes = ($classes ? "{$classes} " : $classes) . implode('_', explode('/', $name)) . '_tool';
        $options = Q_Response::getToolOptions($name);
        if (isset($options)) {
            $friendly_options = str_replace(array('"', '\\/'), array('"', '/'), Q_Html::text(Q::json_encode($options)));
        } else {
            $friendly_options = '';
        }
        $normalized = Q_Utils::normalize($name, '-');
        if (isset($options) or $count > 1) {
            $id = $tool_ids[$name];
            $id_string = $count > 1 ? "{$id} " : '';
            $data_options .= " data-{$normalized}='{$id_string}{$friendly_options}'";
        }
        $names[] = $name;
    }
    if (isset($extra['classes'])) {
        $classes .= ' ' . $extra['classes'];
    }
    $attributes = isset($extra['attributes']) ? ' ' . Q_Html::attributes($extra['attributes']) : '';
    $data_retain = !empty($extra['retain']) || Q_Response::shouldRetainTool($id_prefix) ? " data-Q-retain=''" : '';
    $data_replace = !empty($extra['replace']) || Q_Response::shouldReplaceWithTool($id_prefix) ? " data-Q-replace=''" : '';
    $names = $count === 1 ? ' ' . key($info) : 's ' . implode(" ", $names);
    $ajax = Q_Request::isAjax();
    $result = "<{$tag} id='{$id_prefix}tool' " . "class='Q_tool {$classes}'{$data_options}{$data_retain}{$data_replace}{$attributes}>" . "{$result}</{$tag}>";
    if (!Q_Request::isAjax()) {
        $result = "<!--\nbegin tool{$names}\n-->{$result}<!--\nend tool{$names} \n-->";
    }
    Q_Html::popIdPrefix();
}
示例#2
0
 /**
  * Calculate diplay name from avatar
  * @method displayName
  * @param {array} $options=array()
  *  Associative array of options, which can include:<br/>
  *   @param {boolean} [$options.short] Show one part of the name only
  *   @param {boolean} [$options.show] The parts of the name to show. Can have the letters "f", "l", "u" in any order.
  *   @param {boolean} [$options.html] If true, encloses the first name, last name, username in span tags. If an array, then it will be used as the attributes of the html.
  *   @param {boolean} [$options.escape] If true, does HTML escaping of the retrieved fields
  * @param {string} [$fallback] What to return if there is no info to get displayName from.
  * @return {string|null}
  */
 function displayName($options = array(), $fallback = null)
 {
     $fn = $this->firstName;
     $ln = $this->lastName;
     $u = $this->username;
     if (!empty($options['escape']) or !empty($options['html'])) {
         $fn = Q_Html::text($fn);
         $ln = Q_Html::text($ln);
         $u = Q_Html::text($u);
     }
     if (!empty($options['html'])) {
         $attributes = is_array($options['html']) ? $options['html'] : array();
         $class = isset($attributes['class']) ? ' ' . $attributes['class'] : '';
         $attributes['class'] = "Streams_firstName{$class}";
         $attr = Q_Html::attributes($attributes);
         $fn2 = "<span {$attr}>{$fn}</span>";
         $attributes['class'] = "Streams_lastName{$class}";
         $attr = Q_Html::attributes($attributes);
         $ln2 = "<span {$attr}>{$ln}</span>";
         $attributes['class'] = "Streams_username{$class}";
         $attr = Q_Html::attributes($attributes);
         $u2 = "<span {$attr}>{$u}</span>";
         $f2 = "<span {$attr}>{$fallback}</span>";
     } else {
         $fn2 = $fn;
         $ln2 = $ln;
         $u2 = $u;
         $f2 = $fallback;
     }
     if (!empty($options['short'])) {
         return $fn ? $fn2 : ($u ? $u2 : $f2);
     }
     // $u = $u ? "\"$username\"" : '';
     if (!empty($options['show'])) {
         $show = str_split($options['show']);
         $parts = array();
         foreach ($show as $s) {
             $parts[] = $s == 'f' ? $fn2 : ($s == 'l' ? $ln2 : $u2);
         }
         return implode(' ', $parts);
     }
     if ($fn and $ln) {
         return "{$fn2} {$ln2}";
     } else {
         if ($fn and !$ln) {
             return $u ? "{$fn2} {$u2}" : $fn2;
         } else {
             if (!$fn and $ln) {
                 return $u ? "{$u2} {$ln2}" : $ln2;
             } else {
                 return $u ? $u2 : $f2;
             }
         }
     }
 }