3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
24 define('BACKGROUND_ON', 1);
25 define('BACKGROUND_OFF', 2);
26 define('BACKGROUND_TILE', 4);
29 * Table Definition for design
32 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
33 require_once INSTALLDIR . '/lib/webcolor.php';
35 class Design extends Memcached_DataObject
38 /* the code below is auto generated do not remove the above tag */
40 public $__table = 'design'; // table name
41 public $id; // int(4) primary_key not_null
42 public $backgroundcolor; // int(4)
43 public $contentcolor; // int(4)
44 public $sidebarcolor; // int(4)
45 public $textcolor; // int(4)
46 public $linkcolor; // int(4)
47 public $backgroundimage; // varchar(255)
48 public $disposition; // tinyint(1) default_1
51 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
53 /* the code above is auto generated do not remove the tag below */
56 function showCSS($out)
60 $bgcolor = Design::toWebColor($this->backgroundcolor);
62 if (!empty($bgcolor)) {
63 $css .= 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n";
66 $ccolor = Design::toWebColor($this->contentcolor);
68 if (!empty($ccolor)) {
69 $css .= '#content, #site_nav_local_views .current a { background-color: #';
70 $css .= $ccolor->hexValue() . '} '."\n";
73 $sbcolor = Design::toWebColor($this->sidebarcolor);
75 if (!empty($sbcolor)) {
76 $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n";
79 $tcolor = Design::toWebColor($this->textcolor);
81 if (!empty($tcolor)) {
82 $css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n";
85 $lcolor = Design::toWebColor($this->linkcolor);
87 if (!empty($lcolor)) {
88 $css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n";
91 if (!empty($this->backgroundimage) &&
92 $this->disposition & BACKGROUND_ON) {
94 $repeat = ($this->disposition & BACKGROUND_TILE) ?
95 'background-repeat:repeat;' :
96 'background-repeat:no-repeat;';
98 $css .= 'body { background-image:url(' .
99 Design::url($this->backgroundimage) .
100 '); ' . $repeat . ' background-attachment:fixed; }' . "\n";
103 if (0 != mb_strlen($css)) {
108 static function toWebColor($color)
110 if ($color == null) {
115 return new WebColor($color);
116 } catch (WebColorException $e) {
117 // This shouldn't happen
118 common_log(LOG_ERR, "Unable to create web color for $color",
124 static function filename($id, $extension, $extra=null)
126 return $id . (($extra) ? ('-' . $extra) : '') . $extension;
129 static function path($filename)
131 $dir = common_config('background', 'dir');
133 if ($dir[strlen($dir)-1] != '/') {
137 return $dir . $filename;
140 static function url($filename)
142 $path = common_config('background', 'path');
144 if ($path[strlen($path)-1] != '/') {
148 if ($path[0] != '/') {
152 $server = common_config('background', 'server');
154 if (empty($server)) {
155 $server = common_config('site', 'server');
158 $ssl = common_config('background', 'ssl');
160 if (is_null($ssl)) { // null -> guess
161 if (common_config('site', 'ssl') == 'always' &&
162 !common_config('background', 'server')) {
169 $protocol = ($ssl) ? 'https' : 'http';
171 return $protocol.'://'.$server.$path.$filename;
174 function setDisposition($on, $off, $tile)
177 $this->disposition |= BACKGROUND_ON;
179 $this->disposition &= ~BACKGROUND_ON;
183 $this->disposition |= BACKGROUND_OFF;
185 $this->disposition &= ~BACKGROUND_OFF;
189 $this->disposition |= BACKGROUND_TILE;
191 $this->disposition &= ~BACKGROUND_TILE;
196 * Return a design object based on the configured site design.
198 * @return Design a singleton design object for the site.
201 static function siteDesign()
203 static $siteDesign = null;
205 if (empty($siteDesign)) {
207 $siteDesign = new Design();
209 $attrs = array('backgroundcolor',
217 foreach ($attrs as $attr) {
218 $val = common_config('design', $attr);
219 if ($val !== false) {
220 $siteDesign->$attr = $val;