forked from GNUsocial/gnu-social
Site-wide design configuration
I added some code so that the site-wide design can be set, using the configuration interface. I also moved the configuration option from $config['site']['design']['background'] to just $config['design']['background'], but the old syntax will still work. Conflicts: config.php.sample
This commit is contained in:
parent
421ee4297e
commit
854d24b05a
17
README
17
README
@ -961,9 +961,6 @@ sslserver: use an alternate server name for SSL URLs, like
|
||||
shorturllength: Length of URL at which URLs in a message exceeding 140
|
||||
characters will be sent to the user's chosen
|
||||
shortening service.
|
||||
design: a default design (colors and background) for the site.
|
||||
Sub-items are: backgroundcolor, contentcolor, sidebarcolor,
|
||||
textcolor, linkcolor, backgroundimage, disposition.
|
||||
dupelimit: minimum time allowed for one person to say the same thing
|
||||
twice. Default 60s. Anything lower is considered a user
|
||||
or UI error.
|
||||
@ -1429,6 +1426,20 @@ notify third-party servers of updates.
|
||||
notify: an array of URLs for ping endpoints. Default is the empty
|
||||
array (no notification).
|
||||
|
||||
design
|
||||
------
|
||||
|
||||
Default design (colors and background) for the site. Actual appearance
|
||||
depends on the theme. Null values mean to use the theme defaults.
|
||||
|
||||
backgroundcolor: Hex color of the site background.
|
||||
contentcolor: Hex color of the content area background.
|
||||
sidebarcolor: Hex color of the sidebar background.
|
||||
textcolor: Hex color of all non-link text.
|
||||
linkcolor: Hex color of all links.
|
||||
backgroundimage: Image to use for the background.
|
||||
disposition: Flags for whether or not to tile the background image.
|
||||
|
||||
Plugins
|
||||
=======
|
||||
|
||||
|
@ -55,26 +55,38 @@ class Design extends Memcached_DataObject
|
||||
|
||||
function showCSS($out)
|
||||
{
|
||||
try {
|
||||
$css = '';
|
||||
|
||||
$bgcolor = new WebColor($this->backgroundcolor);
|
||||
$ccolor = new WebColor($this->contentcolor);
|
||||
$sbcolor = new WebColor($this->sidebarcolor);
|
||||
$tcolor = new WebColor($this->textcolor);
|
||||
$lcolor = new WebColor($this->linkcolor);
|
||||
$bgcolor = Design::toWebColor($this->backgroundcolor);
|
||||
|
||||
} catch (WebColorException $e) {
|
||||
// This shouldn't happen
|
||||
common_log(LOG_ERR, "Unable to create color for design $id.",
|
||||
__FILE__);
|
||||
if (!empty($bgcolor)) {
|
||||
$css .= 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n";
|
||||
}
|
||||
|
||||
$css = 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n";
|
||||
$css .= '#content, #site_nav_local_views .current a { background-color: #';
|
||||
$css .= $ccolor->hexValue() . '} '."\n";
|
||||
$css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n";
|
||||
$css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n";
|
||||
$css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n";
|
||||
$ccolor = Design::toWebColor($this->contentcolor);
|
||||
|
||||
if (!empty($ccolor)) {
|
||||
$css .= '#content, #site_nav_local_views .current a { background-color: #';
|
||||
$css .= $ccolor->hexValue() . '} '."\n";
|
||||
}
|
||||
|
||||
$sbcolor = Design::toWebColor($this->sidebarcolor);
|
||||
|
||||
if (!empty($sbcolor)) {
|
||||
$css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n";
|
||||
}
|
||||
|
||||
$tcolor = Design::toWebColor($this->textcolor);
|
||||
|
||||
if (!empty($tcolor)) {
|
||||
$css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n";
|
||||
}
|
||||
|
||||
$lcolor = Design::toWebColor($this->linkcolor);
|
||||
|
||||
if (!empty($lcolor)) {
|
||||
$css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n";
|
||||
}
|
||||
|
||||
if (!empty($this->backgroundimage) &&
|
||||
$this->disposition & BACKGROUND_ON) {
|
||||
@ -88,8 +100,25 @@ class Design extends Memcached_DataObject
|
||||
'); ' . $repeat . ' background-attachment:fixed; }' . "\n";
|
||||
}
|
||||
|
||||
$out->element('style', array('type' => 'text/css'), $css);
|
||||
if (0 != mb_strlen($css)) {
|
||||
$out->element('style', array('type' => 'text/css'), $css);
|
||||
}
|
||||
}
|
||||
|
||||
static function toWebColor($color)
|
||||
{
|
||||
if (is_null($color)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new WebColor($color);
|
||||
} catch (WebColorException $e) {
|
||||
// This shouldn't happen
|
||||
common_log(LOG_ERR, "Unable to create color for design $id.",
|
||||
__FILE__);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static function filename($id, $extension, $extra=null)
|
||||
@ -152,4 +181,33 @@ class Design extends Memcached_DataObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a design object based on the configured site design.
|
||||
*
|
||||
* @return Design a singleton design object for the site.
|
||||
*/
|
||||
|
||||
static function siteDesign()
|
||||
{
|
||||
static $siteDesign = null;
|
||||
|
||||
if (empty($siteDesign)) {
|
||||
|
||||
$siteDesign = new Design();
|
||||
|
||||
$attrs = array('backgroundcolor',
|
||||
'contentcolor',
|
||||
'sidebarcolor',
|
||||
'textcolor',
|
||||
'linkcolor',
|
||||
'backgroundimage',
|
||||
'disposition');
|
||||
|
||||
foreach ($attrs as $attr) {
|
||||
$siteDesign->$attr = common_config('design', $attr);
|
||||
}
|
||||
}
|
||||
|
||||
return $siteDesign;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,14 @@ $config['site']['server'] = 'localhost';
|
||||
$config['site']['path'] = 'laconica';
|
||||
// $config['site']['fancy'] = false;
|
||||
// $config['site']['theme'] = 'default';
|
||||
// Sets the site's default design values
|
||||
// $config['design']['backgroundcolor'] = '#F0F2F5';
|
||||
// $config['design']['contentcolor'] = '#FFFFFF';
|
||||
// $config['design']['sidebarcolor'] = '#CEE1E9';
|
||||
// $config['design']['textcolor'] = '#000000';
|
||||
// $config['design']['linkcolor'] = '#002E6E';
|
||||
// $config['design']['backgroundimage'] = null;
|
||||
// $config['design']['disposition'] = 1;
|
||||
// To enable the built-in mobile style sheet, defaults to false.
|
||||
// $config['site']['mobile'] = true;
|
||||
// For contact email, defaults to $_SERVER["SERVER_ADMIN"]
|
||||
|
@ -191,6 +191,7 @@ class Action extends HTMLOutputter // lawsuit
|
||||
function showStylesheets()
|
||||
{
|
||||
if (Event::handle('StartShowStyles', array($this))) {
|
||||
|
||||
if (Event::handle('StartShowLaconicaStyles', array($this))) {
|
||||
$this->element('link', array('rel' => 'stylesheet',
|
||||
'type' => 'text/css',
|
||||
@ -209,6 +210,7 @@ class Action extends HTMLOutputter // lawsuit
|
||||
'media' => 'print'));
|
||||
Event::handle('EndShowLaconicaStyles', array($this));
|
||||
}
|
||||
|
||||
if (Event::handle('StartShowUAStyles', array($this))) {
|
||||
$this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
|
||||
'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
|
||||
@ -223,6 +225,21 @@ class Action extends HTMLOutputter // lawsuit
|
||||
'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
|
||||
Event::handle('EndShowUAStyles', array($this));
|
||||
}
|
||||
|
||||
if (Event::handle('StartShowDesign', array($this))) {
|
||||
|
||||
$user = common_current_user();
|
||||
|
||||
if (empty($user) || $user->viewdesigns) {
|
||||
$design = $this->getDesign();
|
||||
|
||||
if (!empty($design)) {
|
||||
$design->showCSS($this);
|
||||
}
|
||||
}
|
||||
|
||||
Event::handle('EndShowDesign', array($this));
|
||||
}
|
||||
Event::handle('EndShowStyles', array($this));
|
||||
}
|
||||
}
|
||||
@ -1074,4 +1091,15 @@ class Action extends HTMLOutputter // lawsuit
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A design for this action
|
||||
*
|
||||
* @return Design a design object to use
|
||||
*/
|
||||
|
||||
function getDesign()
|
||||
{
|
||||
return Design::siteDesign();
|
||||
}
|
||||
}
|
||||
|
@ -94,14 +94,6 @@ $config =
|
||||
array('name' => 'Just another Laconica microblog',
|
||||
'server' => $_server,
|
||||
'theme' => 'default',
|
||||
'design' =>
|
||||
array('backgroundcolor' => '#CEE1E9',
|
||||
'contentcolor' => '#FFFFFF',
|
||||
'sidebarcolor' => '#C8D1D5',
|
||||
'textcolor' => '#000000',
|
||||
'linkcolor' => '#002E6E',
|
||||
'backgroundimage' => null,
|
||||
'disposition' => 1),
|
||||
'path' => $_path,
|
||||
'logfile' => null,
|
||||
'logo' => null,
|
||||
@ -261,6 +253,14 @@ $config =
|
||||
'sessions' =>
|
||||
array('handle' => false, // whether to handle sessions ourselves
|
||||
'debug' => false), // debugging output for sessions
|
||||
'design' =>
|
||||
array('backgroundcolor' => null, // null -> 'use theme default'
|
||||
'contentcolor' => null,
|
||||
'sidebarcolor' => null,
|
||||
'textcolor' => null,
|
||||
'linkcolor' => null,
|
||||
'backgroundimage' => null,
|
||||
'disposition' => null),
|
||||
);
|
||||
|
||||
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
|
||||
@ -277,6 +277,10 @@ $config['db'] =
|
||||
'quote_identifiers' => false,
|
||||
'type' => 'mysql' );
|
||||
|
||||
// Backward compatibility
|
||||
|
||||
$config['site']['design'] =& $config['design'];
|
||||
|
||||
if (function_exists('date_default_timezone_set')) {
|
||||
/* Work internally in UTC */
|
||||
date_default_timezone_set('UTC');
|
||||
|
@ -47,33 +47,10 @@ if (!defined('LACONICA')) {
|
||||
|
||||
class CurrentUserDesignAction extends Action
|
||||
{
|
||||
|
||||
/**
|
||||
* Show the user's design stylesheet
|
||||
*
|
||||
* @return nothing
|
||||
*/
|
||||
|
||||
function showStylesheets()
|
||||
{
|
||||
parent::showStylesheets();
|
||||
|
||||
$user = common_current_user();
|
||||
|
||||
if (empty($user) || $user->viewdesigns) {
|
||||
$design = $this->getDesign();
|
||||
|
||||
if (!empty($design)) {
|
||||
$design->showCSS($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A design for this action
|
||||
*
|
||||
* if the user attribute has been set, returns that user's
|
||||
* design.
|
||||
* Returns the design preferences for the current user.
|
||||
*
|
||||
* @return Design a design object to use
|
||||
*/
|
||||
@ -82,11 +59,15 @@ class CurrentUserDesignAction extends Action
|
||||
{
|
||||
$cur = common_current_user();
|
||||
|
||||
if (empty($cur)) {
|
||||
return null;
|
||||
if (!empty($cur)) {
|
||||
|
||||
$design = $cur->getDesign();
|
||||
|
||||
if (!empty($design)) {
|
||||
return $design;
|
||||
}
|
||||
}
|
||||
|
||||
return $cur->getDesign();
|
||||
return parent::getDesign();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,26 +49,6 @@ class GroupDesignAction extends Action {
|
||||
/** The group in question */
|
||||
var $group = null;
|
||||
|
||||
/**
|
||||
* Show the groups's design stylesheet
|
||||
*
|
||||
* @return nothing
|
||||
*/
|
||||
function showStylesheets()
|
||||
{
|
||||
parent::showStylesheets();
|
||||
|
||||
$user = common_current_user();
|
||||
|
||||
if (empty($user) || $user->viewdesigns) {
|
||||
$design = $this->getDesign();
|
||||
|
||||
if (!empty($design)) {
|
||||
$design->showCSS($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A design for this action
|
||||
*
|
||||
@ -80,10 +60,12 @@ class GroupDesignAction extends Action {
|
||||
|
||||
function getDesign()
|
||||
{
|
||||
if (empty($this->group)) {
|
||||
return null;
|
||||
if (!empty($this->group)) {
|
||||
$design = $this->group->getDesign();
|
||||
if (!empty($design)) {
|
||||
return $design;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->group->getDesign();
|
||||
return parent::getDesign();
|
||||
}
|
||||
}
|
||||
|
@ -52,26 +52,6 @@ class OwnerDesignAction extends Action {
|
||||
|
||||
var $user = null;
|
||||
|
||||
/**
|
||||
* Show the owner's design stylesheet
|
||||
*
|
||||
* @return nothing
|
||||
*/
|
||||
function showStylesheets()
|
||||
{
|
||||
parent::showStylesheets();
|
||||
|
||||
$user = common_current_user();
|
||||
|
||||
if (empty($user) || $user->viewdesigns) {
|
||||
$design = $this->getDesign();
|
||||
|
||||
if (!empty($design)) {
|
||||
$design->showCSS($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A design for this action
|
||||
*
|
||||
@ -83,10 +63,15 @@ class OwnerDesignAction extends Action {
|
||||
|
||||
function getDesign()
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
return null;
|
||||
if (!empty($this->user)) {
|
||||
|
||||
$design = $this->user->getDesign();
|
||||
|
||||
if (!empty($design)) {
|
||||
return $design;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->user->getDesign();
|
||||
return parent::getDesign();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user