Exemplo n.º 1
0
	/**
	 * Generates CSS for the font, this is used in TitanFrameworkCSS
	 *
	 * @param	string $css The CSS generated
	 * @param	TitanFrameworkOption $option The current option being processed
	 * @return	string The CSS generated
	 * @since	1.4
	 */
	public function generateCSS( $css, $option ) {
		if ( $this->settings['id'] != $option->settings['id'] ) {
			return $css;
		}

		$value = $this->getFramework()->getOption( $option->settings['id'] );

		$skip = array( 'dark', 'font-type', 'text-shadow-distance', 'text-shadow-blur', 'text-shadow-color', 'text-shadow-opacity' );

		foreach ( $value as $key => $val ) {
			if ( in_array( $key, $skip ) ) {
				continue;
			}

			if ( $key == 'font-family' ) {
				if ( ! empty( $value['font-type'] ) ) {
					if ( $value['font-type'] == 'google' ) {
						$css .= "\$" . $option->settings['id'] . "-" . $key . ": \"" . $value[ $key ] . "\";";
						continue;
					}
				}
				$css .= "\$" . $option->settings['id'] . "-" . $key . ": " . $value[ $key ] . ";";
				continue;
			}

			if ( $key == 'text-shadow-location' ) {
				$textShadow = '';
				if ( $value[ $key ] != 'none' ) {
					if ( stripos( $value[ $key ], 'left' ) !== false ) {
						$textShadow .= '-' . $value['text-shadow-distance'];
					} else if ( stripos( $value[ $key ], 'right' ) !== false ) {
						$textShadow .= $value['text-shadow-distance'];
					} else {
						$textShadow .= '0';
					}
					$textShadow .= ' ';
					if ( stripos( $value[ $key ], 'top' ) !== false ) {
						$textShadow .= '-' . $value['text-shadow-distance'];
					} else if ( stripos( $value[ $key ], 'bottom' ) !== false ) {
						$textShadow .= $value['text-shadow-distance'];
					} else {
						$textShadow .= '0';
					}
					$textShadow .= ' ';
					$textShadow .= $value['text-shadow-blur'];
					$textShadow .= ' ';

					$rgb = tf_hex2rgb( $value['text-shadow-color'] );
					$rgb[] = $value['text-shadow-opacity'];

					$textShadow .= 'rgba(' . implode( ',', $rgb ) . ')';
				} else {
					$textShadow .= $value[ $key ];
				}

				$css .= "\$" . $option->settings['id'] . "-text-shadow: " . $textShadow . ";";
				continue;
			}

			$css .= "\$" . $option->settings['id'] . "-" . $key . ": " . $value[ $key ] . ";";
		}

		/*
		 * There are 2 ways to include the values for the CSS. The normal `value-arraykey`, or just `value`
		 * Using `value` will print out the entire font CSS
		 */

		// Create the entire CSS for the font, this should just be used to replace the `value` variable
		$cssVariables = '';
		$cssVariableArray = array( 'font-family', 'color', 'font-size', 'font-weight', 'font-style', 'line-height', 'letter-spacing',
		'text-transform', 'font-variant', 'text-shadow' );
		foreach ( $cssVariableArray as $param ) {
			$cssVariables .= $param . ": \$" . $option->settings['id'] . "-" . $param . ";\n";
		}

		// Replace the `value` parameters in the given css
		$modifiedCss = '';
		if ( ! empty( $option->settings['css'] ) ) {
			$modifiedCss = $option->settings['css'];
			// if `value` is given, replace it with the entire css we created above in $cssVariables
			$modifiedCss = preg_replace( '/value[^-]/', $cssVariables, $modifiedCss );
			// normal `value-arraykey` values
			$modifiedCss = str_replace( 'value-', '$' . $option->settings['id'] . '-', $modifiedCss );
		}

		$css .= $modifiedCss;

		return $css;
	}
 /**
  * Generates CSS for the font, this is used in TitanFrameworkCSS
  *
  * @param	string $css The CSS generated
  * @param	TitanFrameworkOption $option The current option being processed
  * @return	string The CSS generated
  * @since	1.4
  */
 public function generateCSS($css, $option)
 {
     if ($this->settings['id'] != $option->settings['id']) {
         return $css;
     }
     $value = $this->getFramework()->getOption($option->settings['id']);
     $skip = array('dark', 'font-type', 'text-shadow-distance', 'text-shadow-blur', 'text-shadow-color', 'text-shadow-opacity');
     // If the value is blank, use the defaults
     if (empty($value)) {
         $value = $this->getValue();
         if (is_serialized($value)) {
             $value = unserialize($value);
         }
         if (!is_array($value)) {
             $value = array();
         }
         $value = array_merge(self::$defaultStyling, $value);
     }
     foreach ($value as $key => $val) {
         // Force skip other keys, those are processed under another key, e.g. text-shadow-distance is
         // used by text-shadow-location
         if (in_array($key, $skip)) {
             continue;
         }
         // Don't include keys which are not in the default styles
         if (!in_array($key, array_keys(self::$defaultStyling))) {
             continue;
         }
         if ($key == 'font-family') {
             if (!empty($value['font-type'])) {
                 if ($value['font-type'] == 'google') {
                     $css .= "\$" . $option->settings['id'] . "-" . $key . ": \"" . $value[$key] . "\";";
                     continue;
                 }
             }
             $css .= "\$" . $option->settings['id'] . "-" . $key . ": " . $value[$key] . ";";
             continue;
         }
         if ($key == 'text-shadow-location') {
             $textShadow = '';
             if ($value[$key] != 'none') {
                 if (stripos($value[$key], 'left') !== false) {
                     $textShadow .= '-' . $value['text-shadow-distance'];
                 } else {
                     if (stripos($value[$key], 'right') !== false) {
                         $textShadow .= $value['text-shadow-distance'];
                     } else {
                         $textShadow .= '0';
                     }
                 }
                 $textShadow .= ' ';
                 if (stripos($value[$key], 'top') !== false) {
                     $textShadow .= '-' . $value['text-shadow-distance'];
                 } else {
                     if (stripos($value[$key], 'bottom') !== false) {
                         $textShadow .= $value['text-shadow-distance'];
                     } else {
                         $textShadow .= '0';
                     }
                 }
                 $textShadow .= ' ';
                 $textShadow .= $value['text-shadow-blur'];
                 $textShadow .= ' ';
                 $rgb = tf_hex2rgb($value['text-shadow-color']);
                 $rgb[] = $value['text-shadow-opacity'];
                 $textShadow .= 'rgba(' . implode(',', $rgb) . ')';
             } else {
                 $textShadow .= $value[$key];
             }
             $css .= "\$" . $option->settings['id'] . "-text-shadow: " . $textShadow . ";";
             continue;
         }
         $css .= "\$" . $option->settings['id'] . "-" . $key . ": " . $value[$key] . ";";
     }
     /*
      * There are 2 ways to include the values for the CSS. The normal `value-arraykey`, or just `value`
      * Using `value` will print out the entire font CSS
      */
     // Create the entire CSS for the font, this should just be used to replace the `value` variable
     $cssVariables = '';
     $cssChecking = array('font_family', 'color', 'font_size', 'font_weight', 'font_style', 'line_height', 'letter_spacing', 'text_transform', 'font_variant', 'text_shadow');
     //Enter values that are not marked as false.
     foreach ($cssChecking as $subject) {
         if ($option->settings['show_' . $subject]) {
             $cssVariableArray[] = str_replace("_", "-", $subject);
         }
     }
     //Now, integrate these values with their corresponding keys
     foreach ($cssVariableArray as $param) {
         $cssVariables .= $param . ": \$" . $option->settings['id'] . "-" . $param . ";\n";
     }
     // Replace the `value` parameters in the given css
     $modifiedCss = '';
     if (!empty($option->settings['css'])) {
         $modifiedCss = $option->settings['css'];
         // if `value` is given, replace it with the entire css we created above in $cssVariables
         $modifiedCss = preg_replace('/value[^-]/', $cssVariables, $modifiedCss);
         // normal `value-arraykey` values
         $modifiedCss = str_replace('value-', '$' . $option->settings['id'] . '-', $modifiedCss);
     }
     $css .= $modifiedCss;
     return $css;
 }
/**
 * Get RGBA color format from hex color
 *
 * @return string
 */
function tf_get_rgba_color($color)
{
    $color = explode('_', $color);
    $opacity = isset($color[1]) ? $color[1] : '1';
    return 'rgba(' . tf_hex2rgb($color[0]) . ', ' . $opacity . ')';
}