Advertisement
Guest User

get a XenForo display property

a guest
Feb 5th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. class Sedo_Extra_Helper_Demo
  2. {
  3.     //@ME: CHECK THIS FUNCTION :  $myproperty = XenForo_Template_Helper_Core::styleProperty('myproperty');
  4.     /******
  5.         #GetDisplayValue
  6.  
  7.         This function gets the visual value of a display property. The value is returned in the following array: $return['result']
  8.  
  9.         If it is a color, the following arrays are also available:
  10.         - $return['rgba'], for the rgba color value
  11.         - $return['rgb'], for the rgb color value
  12.         - $return['hexa'], for the hexa color value
  13.  
  14.         For a color, $return['result'] will return the rgba value for all recent browsers
  15.         and will automatically return the rgb value for the old version of Internet Explorer
  16.     ***/
  17.  
  18.  
  19.     public static function GetDisplayValue($property, $defaultvalue)
  20.     {
  21.         $value = array();
  22.         if (XenForo_Application::isRegistered('styles'))
  23.         {
  24.             $style = XenForo_Application::get('styles');
  25.         }
  26.         else
  27.         {
  28.             //ie: for XenForo_Template_Admin
  29.             $style = XenForo_Model::create('XenForo_Model_Style')->getAllStyles();
  30.             XenForo_Application::set('styles', $style);
  31.         }
  32.  
  33.         $visitor = XenForo_Visitor::getInstance();
  34.         $styleid = $visitor['style_id'];
  35.  
  36.         if($styleid == 0)
  37.         {
  38.             $options = XenForo_Application::get('options');
  39.             $styleid = $options->defaultStyleId;
  40.         }
  41.  
  42.         //Get current style properties
  43.         if (isset($style[$styleid]['properties']))
  44.         {
  45.             $properties = $style[$styleid]['properties'];
  46.             $properties = unserialize($properties);
  47.  
  48.             $value['result'] = $properties[$property];
  49.  
  50.  
  51.                 if (!is_array($value['result']) AND preg_match('#rgba#i', $value['result']))
  52.                 {
  53.                 $isBadIE = self::isBadIE();
  54.  
  55.                 $value['rgba'] = $value['result'];
  56.                 $value['rgb'] = XenForo_Helper_Color::unRgba($value['result']);
  57.                 $value['hexa'] = self::rgb2hex($value['rgb']);
  58.  
  59.                 if ($isBadIE == true)
  60.                 {
  61.                     $value['result'] = $value['rgb'];
  62.                 }
  63.                 }
  64.                 elseif (!is_array($value['result']) AND preg_match('#rgb(?!a)#i', $value['result']))
  65.                 {
  66.                 $value['rgba'] = XenForo_Helper_Color::rgba($value['result'], 1);
  67.                 $value['rgb'] = $value['result'];
  68.                 $value['hexa'] = self::rgb2hex($value['rgb']);
  69.                 }
  70.                 elseif ( !is_array($value['result']) ) //don't forget the hexa value options !
  71.                 {
  72.                 $value['rgba'] = XenForo_Helper_Color::rgba($value['result'], 1);
  73.                 $value['rgb'] = XenForo_Helper_Color::unRgba($value['rgba']);
  74.                 $value['hexa'] = self::rgb2hex($value['rgb']);
  75.                 }                  
  76.                 else
  77.                 {
  78.                 $value['rgba'] = $defaultvalue;
  79.                 $value['rgb'] = $defaultvalue;
  80.                 $value['hexa'] = $defaultvalue;
  81.                 }
  82.         }
  83.         else
  84.             {
  85.             $value['result'] = $defaultvalue;
  86.             $value['rgba'] = $defaultvalue;
  87.             $value['rgb'] = $defaultvalue;
  88.             $value['hexa'] = $defaultvalue;
  89.             }
  90.  
  91.             return $value;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement