]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Design.php
Enable tiling of background imgs for Designs
[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     public $tile;                            // tinyint(1)
45
46     /* Static get */
47     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
48
49     /* the code above is auto generated do not remove the tag below */
50     ###END_AUTOCODE
51
52     function showCSS($out)
53     {
54         try {
55
56             $bgcolor = new WebColor($this->backgroundcolor);
57             $ccolor  = new WebColor($this->contentcolor);
58             $sbcolor = new WebColor($this->sidebarcolor);
59             $tcolor  = new WebColor($this->textcolor);
60             $lcolor  = new WebColor($this->linkcolor);
61
62         } catch (WebColorException $e) {
63             // This shouldn't happen
64             common_log(LOG_ERR, "Unable to create color for design $id.",
65                 __FILE__);
66         }
67
68         $css  = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n";
69         $css .= '#content, #site_nav_local_views .current a { background-color: #';
70         $css .= $ccolor->hexValue() . '} '."\n";
71         $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n";
72         $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n";
73         $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n";
74
75         if (!empty($this->backgroundimage)) {
76
77            $repeat = ($this->tile) ? 'background-repeat:repeat;' :
78                'background-repeat:no-repeat;';
79
80             $css .= 'body { background-image:url(' .
81                 Design::url($this->backgroundimage) .
82                 '); ' . $repeat . ' }' . "\n";
83         }
84
85         $out->element('style', array('type' => 'text/css'), $css);
86
87     }
88
89     static function filename($id, $extension, $extra=null)
90     {
91         return $id . (($extra) ? ('-' . $extra) : '') . $extension;
92     }
93
94     static function path($filename)
95     {
96         $dir = common_config('background', 'dir');
97
98         if ($dir[strlen($dir)-1] != '/') {
99             $dir .= '/';
100         }
101
102         return $dir . $filename;
103     }
104
105     static function url($filename)
106     {
107         $path = common_config('background', 'path');
108
109         if ($path[strlen($path)-1] != '/') {
110             $path .= '/';
111         }
112
113         if ($path[0] != '/') {
114             $path = '/'.$path;
115         }
116
117         $server = common_config('background', 'server');
118
119         if (empty($server)) {
120             $server = common_config('site', 'server');
121         }
122
123         // XXX: protocol
124
125         return 'http://'.$server.$path.$filename;
126     }
127
128 }