]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Update background image settings to use bitflags
authorZach Copley <zach@controlyourself.ca>
Wed, 17 Jun 2009 09:35:51 +0000 (02:35 -0700)
committerZach Copley <zach@controlyourself.ca>
Wed, 17 Jun 2009 09:35:51 +0000 (02:35 -0700)
actions/designsettings.php
classes/Design.php
classes/laconica.ini
db/laconica.sql
lib/common.php

index fbec3fc67f80537be89f00f5f13fbfc658113ce7..3dfaddd7bb09288aa2589ab34813a94782b6f892 100644 (file)
@@ -104,37 +104,52 @@ class DesignsettingsAction extends AccountSettingsAction
                                       'value' => ImageFile::maxFileSizeInt()));
         $this->elementEnd('li');
 
-        $this->elementStart('li', array('id' => 'design_background-image_onoff'));
-
         if (!empty($design->backgroundimage)) {
+
+            $this->elementStart('li', array('id' => 'design_background-image_onoff'));
+
             $this->element('img', array('src' =>
                 Design::url($design->backgroundimage)));
-        }
 
-        $this->element('input', array('name' => 'design_background-image_onoff',
-                                      'type' => 'radio',
-                                      'id' => 'design_background-image_on',
-                                      'class' => 'radio',
-                                      'value' => 'true',
-                                      'checked'=> 'checked'));
-        $this->element('label', array('for' => 'design_background-image_on',
-                                      'class' => 'radio'),
-                                      _('On'));
-        $this->element('input', array('name' => 'design_background-image_onoff',
-                                      'type' => 'radio',
-                                      'id' => 'design_background-image_off',
-                                      'class' => 'radio',
-                                      'value' => 'false'));
-        $this->element('label', array('for' => 'design_background-image_off',
-                                      'class' => 'radio'),
-                                      _('Off'));
-        $this->element('p', 'form_guide', _('Turn background image on or off.'));
-        $this->elementEnd('li');
+            $attrs = array('name' => 'design_background-image_onoff',
+                           'type' => 'radio',
+                           'id' => 'design_background-image_on',
+                           'class' => 'radio',
+                           'value' => 'on');
+
+            if ($design->disposition & BACKGROUND_ON) {
+                $attrs['checked'] = 'checked';
+            }
+
+            $this->element('input', $attrs);
+
+            $this->element('label', array('for' => 'design_background-image_on',
+                                          'class' => 'radio'),
+                                          _('On'));
+
+            $attrs = array('name' => 'design_background-image_onoff',
+                           'type' => 'radio',
+                           'id' => 'design_background-image_off',
+                           'class' => 'radio',
+                           'value' => 'off');
+
+            if ($design->disposition & BACKGROUND_OFF) {
+                $attrs['checked'] = 'checked';
+            }
+
+            $this->element('input', $attrs);
+
+            $this->element('label', array('for' => 'design_background-image_off',
+                                          'class' => 'radio'),
+                                          _('Off'));
+            $this->element('p', 'form_guide', _('Turn background image on or off.'));
+            $this->elementEnd('li');
+        }
 
         $this->elementStart('li');
         $this->checkbox('design_background-image_repeat',
                         _('Tile background image'),
-                        $design->tile);
+                        ($design->disposition & BACKGROUND_TILE) ? true : false );
         $this->elementEnd('li');
 
         $this->elementEnd('ul');
@@ -159,7 +174,6 @@ class DesignsettingsAction extends AccountSettingsAction
                                           'value' => '#' . $bgcolor->hexValue()));
             $this->elementEnd('li');
 
-
             $ccolor = new WebColor($design->contentcolor);
 
             $this->elementStart('li');
@@ -346,7 +360,7 @@ class DesignsettingsAction extends AccountSettingsAction
 
             $design->backgroundimage = $defaults['backgroundimage'];
 
-            $deisng->tile = $defaults['tile'];
+            $deisng->disposition = $defaults['disposition'];
 
         } catch (WebColorException $e) {
             common_log(LOG_ERR, _('Bad default color settings: ' .
@@ -377,7 +391,23 @@ class DesignsettingsAction extends AccountSettingsAction
             return;
         }
 
-        $tile = $this->boolean('design_background-image_repeat');
+        $onoff = $this->arg('design_background-image_onoff');
+
+        $on   = false;
+        $off  = false;
+        $tile = false;
+
+        if ($onoff == 'on') {
+            $on = true;
+        } else {
+            $off = true;
+        }
+
+        $repeat = $this->boolean('design_background-image_repeat');
+
+        if ($repeat) {
+            $tile = true;
+        }
 
         $user = common_current_user();
         $design = $user->getDesign();
@@ -392,7 +422,8 @@ class DesignsettingsAction extends AccountSettingsAction
             $design->textcolor       = $tcolor->intValue();
             $design->linkcolor       = $lcolor->intValue();
             $design->backgroundimage = $filepath;
-            $design->tile            = $tile;
+
+            $design->setDisposition($on, $off, $tile);
 
             $result = $design->update($original);
 
@@ -416,7 +447,8 @@ class DesignsettingsAction extends AccountSettingsAction
             $design->textcolor       = $tcolor->intValue();
             $design->linkcolor       = $lcolor->intValue();
             $design->backgroundimage = $filepath;
-            $design->tile            = $tile;
+
+            $design->setDisposition($on, $off, $tile);
 
             $id = $design->insert();
 
@@ -481,16 +513,4 @@ class DesignsettingsAction extends AccountSettingsAction
         $this->showForm(_('Design preferences saved.'), true);
     }
 
-    /**
-     * Reset design settings to previous saved value if any, or
-     * the defaults
-     *
-     * @return void
-     */
-
-    function resetDesign()
-    {
-        $this->showForm(_('Design preferences reset.'), true);
-    }
-
 }
index 4ea176677bdf971c0b97d7afda4e887de5d61263..5b28bf014a7e18e91143062ef161b3ef9b3485b6 100644 (file)
@@ -21,6 +21,10 @@ if (!defined('LACONICA')) {
     exit(1);
 }
 
+define('BACKGROUND_ON', 1);
+define('BACKGROUND_OFF', 2);
+define('BACKGROUND_TILE', 4);
+
 /**
  * Table Definition for design
  */
@@ -41,7 +45,7 @@ class Design extends Memcached_DataObject
     public $textcolor;                       // int(4)
     public $linkcolor;                       // int(4)
     public $backgroundimage;                 // varchar(255)
-    public $tile;                            // tinyint(1)
+    public $disposition;                     // tinyint(1)   default_1
 
     /* Static get */
     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
@@ -72,9 +76,11 @@ class Design extends Memcached_DataObject
         $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n";
         $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n";
 
-        if (!empty($this->backgroundimage)) {
+        if (!empty($this->backgroundimage) &&
+            $this->disposition & BACKGROUND_ON) {
 
-           $repeat = ($this->tile) ? 'background-repeat:repeat;' :
+           $repeat = ($this->disposition & BACKGROUND_TILE) ?
+               'background-repeat:repeat;' :
                'background-repeat:no-repeat;';
 
             $css .= 'body { background-image:url(' .
@@ -125,4 +131,25 @@ class Design extends Memcached_DataObject
         return 'http://'.$server.$path.$filename;
     }
 
+    function setDisposition($on, $off, $tile)
+    {
+        if ($on) {
+            $this->disposition |= BACKGROUND_ON;
+        } else {
+            $this->disposition &= ~BACKGROUND_ON;
+        }
+
+        if ($off) {
+            $this->disposition |= BACKGROUND_OFF;
+        } else {
+            $this->disposition &= ~BACKGROUND_OFF;
+        }
+
+        if ($tile) {
+            $this->disposition |= BACKGROUND_TILE;
+        } else {
+            $this->disposition &= ~BACKGROUND_TILE;
+        }
+    }
+
 }
index 56968198487d98d0763531b6db67bd1e86dc1e92..1a650aba552583b408feb53cc5df38ebf3129d04 100755 (executable)
@@ -46,7 +46,7 @@ sidebarcolor = 1
 textcolor = 1
 linkcolor = 1
 backgroundimage = 2
-tile = 17
+disposition = 17
 
 [design__keys]
 id = N
index 1f302de167a45a0ea5532ee97fa8221ea53fbc9e..b018afec8ee0f1472261876cb72bf8df7cb2ea31 100644 (file)
@@ -496,7 +496,7 @@ create table design (
     textcolor integer comment 'text color',
     linkcolor integer comment 'link color',
     backgroundimage varchar(255) comment 'background image, if any',
-    tile tinyint default 0 comment 'tile background image'
+    disposition tinyint default 1 comment 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table group_block (
index 629fee25b269b65721e2ee8022b141b2984a5abc..bcf2e5d0c7dfaefa0bc8e3ab266cc50ed7007888 100644 (file)
@@ -79,7 +79,7 @@ $config =
                     'textcolor' => '#000000',
                     'linkcolor' => '#002E6E',
                     'backgroundimage' => null,
-                    'tile' => true),
+                    'disposition' => 1),
               'path' => $_path,
               'logfile' => null,
               'logo' => null,