array(), 'designkit_colorpicker' => array(), 'designkit' => array( 'template' => 'designkit', 'arguments' => array('color' => array()), ), ); } /** * Turn design choices into theme variables. */ function designkit_preprocess_page(&$vars) { $info = designkit_get_info(); if (!empty($info['designkit']['color'])) { $color = variable_get('designkit_color', $info['designkit']['color']); if ($color && array_filter($color, 'designkit_valid_color')) { // Add in designkit styles. $vars['body_classes'] .= " designkit"; // Add styles to closure -- safest way to affect the page. $vars['closure'] .= theme('designkit', $color); } } if (!empty($info['designkit']['logo'])) { $logo = variable_get('designkit_logo', array()); foreach ($logo as $name => $fid) { $file = db_fetch_object(db_query('SELECT * FROM {files} f WHERE f.fid = %d', $fid)); if ($file && $file->filepath && file_exists($file->filepath)) { $vars[$name] = theme('designkit_logo', $name, $file->filepath); } } } } /** * Implementation of hook_imagecache_default_presets(). */ function designkit_imagecache_default_presets() { $presets = array(); // Generate imagecache presets per logo entry in theme info. $info = designkit_get_info(); if (!empty($info['designkit']['logo'])) { foreach ($info['designkit']['logo'] as $name => $params) { list($action, $dimensions) = explode(':', $params); list($width, $height) = explode('x', $dimensions); $valid_actions = imagecache_action_definitions(); if (isset($valid_actions[$action]) && is_numeric($width) && is_numeric($height)) { $presets["designkit-logo-{$name}"] = array ( 'presetname' => "designkit-logo-{$name}", 'actions' => array ( 0 => array ( 'weight' => '0', 'module' => 'imagecache', 'action' => $action, 'data' => array ( // @TODO: decide what to do with this hardcoded param. 'fit' => 'inside', 'width' => $width, 'height' => $height, ), ), ), ); } } } return $presets; } /** * Determine whether a given color string is valid. * Must be in the form of #ffffff (6 digit hex with preceding #) or * #fff (3 digit hex with preceding #). */ function designkit_valid_color($color) { $matches = array(); preg_match('/(#[0-9a-f]{6}|#[0-9a-f]{3})/i', $color, $matches); if ($matches && (strlen($color) === 7 || strlen($color) === 3)) { return TRUE; } return FALSE; } /** * Retrieve designkit info for the site's default theme. */ function designkit_get_info($reset = FALSE) { static $info; if (!isset($info) || $reset) { global $theme_key, $theme_info; if (isset($theme_info, $theme_key) && $theme_key == variable_get('theme_default', 'garland')) { $info = $theme_info->info; } else { $default = variable_get('theme_default', 'garland'); $result = db_query("SELECT name,type,info FROM {system} WHERE type = 'theme' AND name = '%s'", $default); while ($row = db_fetch_object($result)) { $info = unserialize($row->info); } } } return isset($info) ? $info : FALSE; } /** * Apply a shift color to a source color by a certain opacity value. */ function designkit_colorshift($source, $shift, $opacity = .5) { if (designkit_valid_color($source) && designkit_valid_color($shift)) { $source = _color_unpack($source, TRUE); $shift = _color_unpack($shift, TRUE); $shifted = array(); foreach (array_keys($source) as $key) { // shifted = original color + (difference * opacity). $shifted[$key] = $source[$key] + (($shift[$key] - $source[$key]) * $opacity); } return _color_pack($shifted, TRUE); } return $source; } /** * Retrieve the HSL of a color, or the specified component. */ function designkit_colorhsl($source, $key = NULL) { if (designkit_valid_color($source)) { $source = _color_unpack($source, TRUE); $hsl = _color_rgb2hsl($source); $keys = array('h' => 0, 's' => 1, 'l' => 2); if (isset($key, $keys[$key])) { return isset($hsl[$keys[$key]]) ? $hsl[$keys[$key]] : NULL; } return $hsl; } return NULL; } /** * Spaces integration. * Implementation of hook_form_alter() for spaces_features_form. */ function designkit_form_spaces_features_form_alter(&$form, &$form_state) { module_load_include('inc', 'designkit', 'designkit.admin'); _designkit_form_alter($form, $form_state); } /** * Theme integration. * Implementation of hook_form_alter() for system_theme_settings. */ function designkit_form_system_theme_settings_alter(&$form, &$form_state) { module_load_include('inc', 'designkit', 'designkit.admin'); _designkit_form_alter($form, $form_state); // yank the logo if DesignKit will provide one with the same key. $form['logo']['#access'] = !isset($form['designkit_logo']['logo']); // system_theme_settings form requires an additional submit handler. $form['#submit'][] = '_designkit_system_theme_settings_submit'; } /** * Preprocessor for theme('designkit'). */ function template_preprocess_designkit(&$vars) { // Map each color to a corresponding variable name. foreach ($vars['color'] as $key => $color) { $vars[$key] = $color; } } /** * Make logo markup overridable. */ function theme_designkit_logo($name, $filepath) { return theme('imagecache', "designkit-logo-{$name}", $filepath); } /** * Theme colorpicker element. */ function theme_designkit_colorpicker($element) { // Add Farbtastic color picker drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE); drupal_add_js('misc/farbtastic/farbtastic.js'); drupal_add_js(drupal_get_path('module', 'designkit') .'/designkit.js'); $output = theme('textfield', $element); $output .= "
"; return $output; }