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 || $color === '') {
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 if (StatusNet::isHTTPS()) {
144 $sslserver = common_config('background', 'sslserver');
146 if (empty($sslserver)) {
147 // XXX: this assumes that background dir == site dir + /background/
148 // not true if there's another server
149 if (is_string(common_config('site', 'sslserver')) &&
150 mb_strlen(common_config('site', 'sslserver')) > 0) {
151 $server = common_config('site', 'sslserver');
152 } else if (common_config('site', 'server')) {
153 $server = common_config('site', 'server');
155 $path = common_config('site', 'path') . '/background/';
157 $server = $sslserver;
158 $path = common_config('background', 'sslpath');
160 $path = common_config('background', 'path');
168 $path = common_config('background', 'path');
170 $server = common_config('background', 'server');
172 if (empty($server)) {
173 $server = common_config('site', 'server');
179 if ($path[strlen($path)-1] != '/') {
183 if ($path[0] != '/') {
187 return $protocol.'://'.$server.$path.$filename;
190 function setDisposition($on, $off, $tile)
193 $this->disposition |= BACKGROUND_ON;
195 $this->disposition &= ~BACKGROUND_ON;
199 $this->disposition |= BACKGROUND_OFF;
201 $this->disposition &= ~BACKGROUND_OFF;
205 $this->disposition |= BACKGROUND_TILE;
207 $this->disposition &= ~BACKGROUND_TILE;
212 * Return a design object based on the configured site design.
214 * @return Design a singleton design object for the site.
217 static function siteDesign()
219 static $siteDesign = null;
221 if (empty($siteDesign)) {
223 $siteDesign = new Design();
225 $attrs = array('backgroundcolor',
233 foreach ($attrs as $attr) {
234 $val = common_config('design', $attr);
235 if ($val !== false) {
236 $siteDesign->$attr = $val;