]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Design.php
Merge branch '0.8.x' into notice-search-no-results
[quix0rs-gnu-social.git] / classes / Design.php
1 <?php
2 /*
3  * Laconica - the distributed open-source microblogging tool
4  * Copyright (C) 2009, Control Yourself, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) {
21     exit(1);
22 }
23
24 define('BACKGROUND_ON', 1);
25 define('BACKGROUND_OFF', 2);
26 define('BACKGROUND_TILE', 4);
27
28 /**
29  * Table Definition for design
30  */
31
32 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
33 require_once INSTALLDIR . '/lib/webcolor.php';
34
35 class Design extends Memcached_DataObject
36 {
37     ###START_AUTOCODE
38     /* the code below is auto generated do not remove the above tag */
39
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
49
50     /* Static get */
51     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
52
53     /* the code above is auto generated do not remove the tag below */
54     ###END_AUTOCODE
55
56     function showCSS($out)
57     {
58         try {
59
60             $bgcolor = new WebColor($this->backgroundcolor);
61             $ccolor  = new WebColor($this->contentcolor);
62             $sbcolor = new WebColor($this->sidebarcolor);
63             $tcolor  = new WebColor($this->textcolor);
64             $lcolor  = new WebColor($this->linkcolor);
65
66         } catch (WebColorException $e) {
67             // This shouldn't happen
68             common_log(LOG_ERR, "Unable to create color for design $id.",
69                 __FILE__);
70         }
71
72         $css  = 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n";
73         $css .= '#content, #site_nav_local_views .current a { background-color: #';
74         $css .= $ccolor->hexValue() . '} '."\n";
75         $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n";
76         $css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n";
77         $css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n";
78
79         if (!empty($this->backgroundimage) &&
80             $this->disposition & BACKGROUND_ON) {
81
82            $repeat = ($this->disposition & BACKGROUND_TILE) ?
83                'background-repeat:repeat;' :
84                'background-repeat:no-repeat;';
85
86             $css .= 'body { background-image:url(' .
87                 Design::url($this->backgroundimage) .
88                 '); ' . $repeat . ' }' . "\n";
89         }
90
91         $out->element('style', array('type' => 'text/css'), $css);
92
93     }
94
95     static function filename($id, $extension, $extra=null)
96     {
97         return $id . (($extra) ? ('-' . $extra) : '') . $extension;
98     }
99
100     static function path($filename)
101     {
102         $dir = common_config('background', 'dir');
103
104         if ($dir[strlen($dir)-1] != '/') {
105             $dir .= '/';
106         }
107
108         return $dir . $filename;
109     }
110
111     static function url($filename)
112     {
113         $path = common_config('background', 'path');
114
115         if ($path[strlen($path)-1] != '/') {
116             $path .= '/';
117         }
118
119         if ($path[0] != '/') {
120             $path = '/'.$path;
121         }
122
123         $server = common_config('background', 'server');
124
125         if (empty($server)) {
126             $server = common_config('site', 'server');
127         }
128
129         // XXX: protocol
130
131         return 'http://'.$server.$path.$filename;
132     }
133
134     function setDisposition($on, $off, $tile)
135     {
136         if ($on) {
137             $this->disposition |= BACKGROUND_ON;
138         } else {
139             $this->disposition &= ~BACKGROUND_ON;
140         }
141
142         if ($off) {
143             $this->disposition |= BACKGROUND_OFF;
144         } else {
145             $this->disposition &= ~BACKGROUND_OFF;
146         }
147
148         if ($tile) {
149             $this->disposition |= BACKGROUND_TILE;
150         } else {
151             $this->disposition &= ~BACKGROUND_TILE;
152         }
153     }
154
155 }