• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Get Style Properties in phpcode

R

ragtek

Guest
#2
ok found it

PHP:
/** @var $styleModel XenForo_Model_StyleProperty */
            $styleModel = XenForo_Model::create('XenForo_Model_StyleProperty');
              $visitor = XenForo_Visitor::getInstance();

            $background = $styleModel->getStylePropertyDefinitionByNameAndStyle('pageBackground', $visitor['style_id']);
            $background = $background['property_value'];
But any chance to get the value as hexdecimal?
I need this for a javascript
I've tried it with the XenForo_Helper_Color Methods, but i got always the same value back ( rgb(240,240,240) )
 

cclaerhout

Well-known member
#3
I found this method:

Code:
    public static function rgb2hex($color)
    {
        //Match R, G, B values
        preg_match('#^rgb\((?P<r>\d{1,3}).+?(?P<g>\d{1,3}).+?(?P<b>\d{1,3})\)$#i', $color, $rgb);
        //Convert them in hexa
        //Code source: http://forum.codecall.net/php-tutorials/22589-rgb-hex-colors-hex-colors-rgb-php.html                
        $output = sprintf("%x", ($rgb['r'] << 16) + ($rgb['g'] << 8) + $rgb['b']);
        
               return $output;
    }
 

cclaerhout

Well-known member
#4
I continue this thread because the method of Ragtek(...):

Code:
/** @var $styleModel XenForo_Model_StyleProperty */
            $styleModel = XenForo_Model::create('XenForo_Model_StyleProperty');
              $visitor = XenForo_Visitor::getInstance();
 
            $background = $styleModel->getStylePropertyDefinitionByNameAndStyle('pageBackground', $visitor['style_id']);
            $background = $background['property_value'];
(...) only works with the master style. I don't know why but the function 'getStylePropertyDefinitionByNameAndStyle' doesn't allow to get value for styles other than the master one (id:0), even if this value is defined both in the master and 'child' theme. I've found a solution but I'm wondering if there was an easiest way to perform this. 'My' method:

EDIT: DO NOT USE THE CODE BELOW
Code:
        //Get styles options
        $style = XenForo_Model::create('XenForo_Model_StyleProperty');
        //Get visitor information (to know which style he is using
        $visitor = XenForo_Visitor::getInstance();
        //Get Slideshow Background value
            $background_id = $style->getStylePropertyDefinitionByNameAndStyle('sedo_picasa_background', 0);
            $background_id = $background_id['property_definition_id'];
            $background = $style->getStylePropertyByDefinitionAndStyle($background_id, $visitor['style_id']);
            if(empty($background))
            {
                $background = $style->getStylePropertyByDefinitionAndStyle($background_id, 0);
            }
            $background = $background ['property_value'];
 

cclaerhout

Well-known member
#6
FOUND IT !

Code:
//Get styles datas
$style = XenForo_Application::get('styles');
 
//Get visitor style ID
$visitor = XenForo_Visitor::getInstance();
$styleid = $visitor['style_id'];
 
//Get current style properties
$properties = $style[$styleid]['properties'];
$properties = unserialize($properties);
 
//Get your CSS value
$your_css_value = $properties['your_css_name'];
Query used: 0
:)
 

cclaerhout

Well-known member
#7
...
.......
PHP:
$myproperty = XenForo_Template_Helper_Core::styleProperty('myproperty');
=> i have missed this one... the value will automatically change per user style