]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Design.php
Design settings now save and displays backgrounds
[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 /**
25  * Table Definition for design
26  */
27
28 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
29 require_once INSTALLDIR . '/lib/webcolor.php';
30
31 class Design extends Memcached_DataObject
32 {
33     ###START_AUTOCODE
34     /* the code below is auto generated do not remove the above tag */
35
36     public $__table = 'design';                          // table name
37     public $id;                              // int(4)  primary_key not_null
38     public $backgroundcolor;                 // int(4)
39     public $contentcolor;                    // int(4)
40     public $sidebarcolor;                    // int(4)
41     public $textcolor;                       // int(4)
42     public $linkcolor;                       // int(4)
43     public $backgroundimage;                 // varchar(255)
44
45     /* Static get */
46     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
47
48     /* the code above is auto generated do not remove the tag below */
49     ###END_AUTOCODE
50
51     function showCSS($out)
52     {
53         try {
54
55             $bgcolor = new WebColor($this->backgroundcolor);
56             $ccolor  = new WebColor($this->contentcolor);
57             $sbcolor = new WebColor($this->sidebarcolor);
58             $tcolor  = new WebColor($this->textcolor);
59             $lcolor  = new WebColor($this->linkcolor);
60
61         } catch (WebColorException $e) {
62             // This shouldn't happen
63             common_log(LOG_ERR, "Unable to create color for design $id.",
64                 __FILE__);
65         }
66
67         $css  = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n";
68         $css .= '#content, #site_nav_local_views .current a { background-color: #';
69         $css .= $ccolor->hexValue() . '} '."\n";
70         $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n";
71         $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n";
72         $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n";
73
74         if (!empty($this->backgroundimage)) {
75
76             $css .= 'body { background-image:url(' .
77                 Design::url($this->backgroundimage) .
78                 '); background-repeat:no-repeat; }' . "\n";
79         }
80
81         $out->element('style', array('type' => 'text/css'), $css);
82
83     }
84
85     static function filename($id, $extension, $extra=null)
86     {
87         return $id . (($extra) ? ('-' . $extra) : '') . $extension;
88     }
89
90     static function path($filename)
91     {
92         $dir = common_config('background', 'dir');
93
94         if ($dir[strlen($dir)-1] != '/') {
95             $dir .= '/';
96         }
97
98         return $dir . $filename;
99     }
100
101     static function url($filename)
102     {
103         $path = common_config('background', 'path');
104
105         if ($path[strlen($path)-1] != '/') {
106             $path .= '/';
107         }
108
109         if ($path[0] != '/') {
110             $path = '/'.$path;
111         }
112
113         $server = common_config('background', 'server');
114
115         if (empty($server)) {
116             $server = common_config('site', 'server');
117         }
118
119         // XXX: protocol
120
121         return 'http://'.$server.$path.$filename;
122     }
123
124 }