Returns the brightness of a color.
public static brightness ( string $color ) : integer | ||
$color | string | An HTML color, e.g.: #ffffcc. |
Результат | integer | The brightness on a scale of 0 to 255. |
/** * Returns the foreground color. * * @return string A HTML color code. */ public function foregroundColor() { return Horde_Image::brightness($this->backgroundColor()) < 128 ? '#fff' : '#000'; }
/** * Adds a row to the sidebar. * * If containers/sections are not added explicitly to the view * through the "containers" property, these rows will be used * instead. * * @param array $row A hash with the row information. Possible * values: * - label: (string) The row text. * - selected: (boolean) Whether to mark the row as active. * - style: (string) Additional CSS styles to apply to the row. * - url (string) URL to link the row to. * - type (string, optional) The row type, defaults to "tree". Further * $row properties depending on the type: * - tree: * - cssClass: (string) CSS class for the icon. * - id: (string) DOM ID for the row link. * - checkbox: * - radiobox: * - color: (string, optional) Background color. * - edit: (string, optional) URL for extra edit icon. * @param string $container If using multiple sidebar sections, the ID of * the section to add the row to. Sections will * be rendered in the order of their first usage. */ public function addRow(array $row, $container = '') { if (!isset($this->containers[$container])) { $this->containers[$container] = array('rows' => array()); if ($container) { $this->containers[$container]['id'] = $container; } } $boxrow = isset($row['type']) && ($row['type'] == 'checkbox' || $row['type'] == 'radiobox'); $label = htmlspecialchars($row['label']); if (isset($row['url'])) { $url = empty($row['url']) ? new Horde_Url() : $row['url']; if ($boxrow) { $attributes = array(); } else { $ak = Horde::getAccessKey($label); $attributes = $ak ? array('accesskey' => $ak) : array(); } foreach (array('onclick', 'target', 'class') as $attribute) { if (!empty($row[$attribute])) { $attributes[$attribute] = $row[$attribute]; } } if ($boxrow) { $class = 'horde-resource-' . (empty($row['selected']) ? 'off' : 'on'); if ($row['type'] == 'radiobox') { $class .= ' horde-radiobox'; } if (empty($attributes['class'])) { $attributes['class'] = $class; } else { $attributes['class'] .= ' ' . $class; } $row['link'] = $url->link($attributes) . $label . '</a>'; } else { $row['link'] = $url->link($attributes) . Horde::highlightAccessKey($label, $ak) . '</a>'; } } else { $row['link'] = '<span class="horde-resource-none">' . $label . '</span>'; } if ($boxrow) { $this->containers[$container]['type'] = $row['type']; if (!isset($row['style'])) { $row['style'] = ''; } if (!isset($row['color'])) { $row['color'] = '#dddddd'; } $foreground = '000'; if (Horde_Image::brightness($row['color']) < 128) { $foreground = 'fff'; } if (strlen($row['style'])) { $row['style'] .= ';'; } $row['style'] .= 'background-color:' . $row['color'] . ';color:#' . $foreground; if (isset($row['edit'])) { $row['editLink'] = $row['edit']->link(array('title' => _("Edit"), 'class' => 'horde-resource-edit-' . $foreground)) . '►' . '</a>'; } } $this->containers[$container]['rows'][] = $row; }
/** * Returns the foreground color for each of the user's categories. * * @return array A list of colors, key is the category name, value is the * HTML color code. */ public static function fgColors() { $colors = self::colors(); $fgcolors = array(); foreach ($colors as $name => $color) { $fgcolors[$name] = Horde_Image::brightness($color) < 128 ? '#f6f6f6' : '#000'; } return $fgcolors; }
/** * Returns the foreground color for a calendar or a background color. * * @param array|Horde_Share_Object|string $calendar A color string, a * calendar share or a * hash from a remote * calender definition. * * @return string A HTML color code. */ public static function foregroundColor($calendar) { return Horde_Image::brightness(is_string($calendar) ? $calendar : self::backgroundColor($calendar)) < 128 ? '#fff' : '#000'; }
protected function _renderVarInput_colorpicker($form, &$var, &$vars) { global $registry, $browser; $varname = $this->_genID($var->getVarName(), false); $color = $var->getValue($vars); if ($color) { $style = ' style="background-color:' . $color . ';color:' . (Horde_Image::brightness($color) < 128 ? '#fff' : '#000') . '"'; } else { $style = ''; } $html = '<table cellspacing="0"><tr><td>' . '<input type="text" size="10" maxlength="7" name="' . htmlspecialchars($var->getVarName()) . '" id="' . $varname . '"' . $style . ' value="' . htmlspecialchars($color) . '" /></td>'; if ($browser->hasFeature('javascript')) { $GLOBALS['injector']->getInstance('Horde_PageOutput')->addScriptFile('colorpicker.js', 'horde'); $html .= '<td>' . Horde::link('#', Horde_Core_Translation::t("Color Picker"), '', '', 'new ColorPicker({ color: \'' . htmlspecialchars($color) . '\', offsetParent: Event.element(event), update: [[\'' . $varname . '\', \'value\'], [\'' . $varname . '\', \'background\']] }); return false;') . Horde::img('colorpicker.png', Horde_Core_Translation::t("Color Picker"), 'height="16"') . '</a></td>'; } return $html . '</tr></table>'; }
protected function _renderVarDisplay_colorpicker($form, &$var, &$vars) { $color = $var->getValue($vars); return '<span style="background-color:' . $color . ';color:' . (Horde_Image::brightness($color) < 128 ? '#fff' : '#000') . '">' . $color . '</span>'; }
/** */ public function __get($name) { switch ($name) { case 'bgcolor': return $this->_bgcolor ? $this->_bgcolor : self::DEFAULT_BG; case 'bgdefault': return $this->bgcolor == self::DEFAULT_BG; case 'canset': return $this->_canset; case 'css': return $this->_css; case 'cssicon': return $this->_cssIcon ? $this->_cssIcon : $this->_css; case 'span': return $this->_css ? '<span class="iconImg msgflags ' . $this->css . '" title="' . htmlspecialchars($this->label) . '"> </span>' : ''; case 'fgcolor': return Horde_Image::brightness($this->bgcolor) < 128 ? '#f6f6f6' : '#000'; case 'form_set': return $this->id; case 'form_unset': return '0\\' . $this->id; case 'hash': return hash('md5', $this->id); case 'id': return $this->_id; case 'label': return $this->getLabel(); } }