summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.cvsignore3
-rw-r--r--README.txt54
-rw-r--r--delta.info2
-rw-r--r--delta.install122
-rw-r--r--delta.module51
-rw-r--r--delta_ui.admin.inc463
-rw-r--r--delta_ui.info10
-rw-r--r--delta_ui.js6
-rw-r--r--delta_ui.module227
-rw-r--r--plugins/context_reaction_delta.inc53
10 files changed, 991 insertions, 0 deletions
diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 0000000..94bbfc6
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1,3 @@
+.gitignore
+.git
+SVN
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..a6365f0
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,54 @@
+$Id$
+##########################################################################################
+ _ _ _ _
+ __| | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ __ _ ___ ___| | _____
+ / _` |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| / _` |/ _ \/ _ \ |/ / __|
+ | (_| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | (_| | __/ __/ <\__ \
+ \__,_|\___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| \__, |\___|\___|_|\_\___/
+ |_| |___/
+##########################################################################################
+
+##########################################################################################
+##### Delta Module
+##########################################################################################
+Project Page: http://drupal.org/project/delta
+Issue Queue: http://drupal.org/project/issues/delta
+Usage Stats: http://drupal.org/project/usage/delta
+Maintainer(s): Jake Strawn
+ http://himerus.com
+ http://developmentgeeks.com
+ http://facebook.com/developmentgeeks
+ http://drupal.org/user/159141
+ http://twitter.com/himerus
+##########################################################################################
+
+Delta Module Information
+========================
+The Delta module enables contextual theme settings for Omega (drupal.org/project/omega)
+subthemes. The combination of Delta, Omega and Context will give you the ability to create
+duplicates of theme settings and via Context assign them as a reaction to any context you
+can create.
+
+Usage
+=====
+
+ 1.) Download and install the Delta & Context modules
+ 2.) Download and enable an Omega Subtheme
+ a.) http://drupal.org/project/omega (Omega Base theme & Starterkit)
+ b.) http://drupal.org/project/gamma (Gamma subtheme)
+ 3.) Visit /admin/appearance and configure the defaults for your Omega subtheme
+ 4.) Visit /admin/appearance/delta and select the checkbox for the appropriate subtheme
+ on the default settings tab
+ 5.) Visit /admin/appearance/delta/templates/add and create your first template.
+ a.) Give it a pretty name
+ b.) Select your theme from the dropdown & save
+ 6.) Automatically directed to /admin/appearance/delta/templates/configure/your-template,
+ you will be able to customize the settings for this special copy of the theme settings.
+ 7.) Visit /admin/structure/context, and add or edit a context with your conditions
+ 8.) Select Delta from the reactions box, and select the appropriate Delta template you
+ just created.
+ 9.) Save and Enjoy...
+
+Related Information
+===================
+ * http://himerus.com/blog/himerus/omega-intro-2-delta-module-contextual-theme-settings \ No newline at end of file
diff --git a/delta.info b/delta.info
index 7f31cac..0bed056 100644
--- a/delta.info
+++ b/delta.info
@@ -4,4 +4,6 @@ description = The Delta Theme Settings API is an advanced manipulation of the Th
package = Theme Tools
core = 7.x
+dependencies[] = context
+
files[] = delta.module
diff --git a/delta.install b/delta.install
new file mode 100644
index 0000000..087cb25
--- /dev/null
+++ b/delta.install
@@ -0,0 +1,122 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Contains install, update, and uninstall functions for Skinr.
+ */
+
+/**
+ * Implementation of hook_schema.
+ */
+function delta_schema() {
+ $schema['delta_theme_settings'] = array(
+ 'description' => t('Stores theme-settings templates that allow overriding the theme settings used based on various contexts.'),
+ 'fields' => array(
+ 'tid' => array(
+ 'description' => 'The unique ID of the theme settings template',
+ 'type' => 'serial',
+ 'length' => 5,
+ 'not null' => TRUE,
+ ),
+ 'name' => array(
+ 'description' => 'The friendly name of this theme settings template.',
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'system_name' => array(
+ 'description' => 'The system name of this theme settings template.',
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'theme' => array(
+ 'description' => 'The theme for which this theme settings template is relevant.',
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'data' => array(
+ 'description' => t('Serialized data which is a copy of the theme settings array stored in the system table based on these overrides'),
+ 'type' => 'text',
+ 'size' => 'big',
+ 'not null' => TRUE,
+ 'serialize' => TRUE,
+ ),
+ ),
+ 'primary key' => array('tid'),
+ 'indexes' => array(
+ 'theme' => array('theme'),
+ 'system_name' => array('system_name'),
+ 'tid' => array('tid'),
+ ),
+ );
+
+ $schema['delta_theme_overrides'] = array(
+ 'description' => t('Override criteria for when to display an alternate theme settings template.'),
+ 'fields' => array(
+ 'did' => array(
+ 'description' => 'The unique ID of the theme settings override',
+ 'type' => 'serial',
+ 'length' => 5,
+ 'not null' => TRUE,
+ ),
+ 'tid' => array(
+ 'description' => t('The template id this override uses. Relates to the tid field in {delta_theme_settings}'),
+ 'type' => 'int',
+ 'length' => 5,
+ 'not null' => TRUE,
+ ),
+ 'name' => array(
+ 'description' => 'The friendly name of this theme settings override.',
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'system_name' => array(
+ 'description' => 'The system name of this theme settings override.',
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'condition' => array(
+ 'description' => t('The condition in which this override fires.'),
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'weight' => array(
+ 'description' => t('Weight field to prioritize the override.'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+ 'status' => array(
+ 'description' => 'Boolean indicating whether or not this item is enabled.',
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+ ),
+ 'primary key' => array('did'),
+ );
+
+ return $schema;
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function delta_uninstall() {
+ // Remove all skinr variables.
+ db_delete('variable')
+ ->condition('name', 'delta_%', 'LIKE')
+ ->execute();
+} \ No newline at end of file
diff --git a/delta.module b/delta.module
index 13bb990..1518916 100644
--- a/delta.module
+++ b/delta.module
@@ -1,2 +1,53 @@
<?php
// $Id$
+
+/**
+ * @file Provide contextual theme settings via context module
+ */
+
+/**
+ * Implementation of hook_context_plugins().
+ *
+ * This is a ctools plugins hook.
+ */
+function delta_context_plugins() {
+ $plugins = array();
+ $plugins['context_reaction_delta'] = array(
+ 'handler' => array(
+ 'path' => drupal_get_path('module', 'delta') .'/plugins',
+ 'file' => 'context_reaction_delta.inc',
+ 'class' => 'context_reaction_delta',
+ 'parent' => 'context_reaction',
+ ),
+ );
+ return $plugins;
+}
+
+/**
+ * Implementation of hook_context_registry().
+ */
+function delta_context_registry() {
+ $registry = array();
+ $registry['reactions']['delta'] = array(
+ 'title' => t('Delta'),
+ 'description' => t('Apply contextual theme settings via the Delta module.'),
+ 'plugin' => 'context_reaction_delta',
+ );
+ return $registry;
+}
+
+/**
+ * Implementation of hook_context_page_reaction().
+ */
+function delta_context_page_reaction() {
+
+}
+
+/**
+ * Implementation of hook_page_alter().
+ */
+function delta_preprocess_page(&$vars) {
+ if ($plugin = context_get_plugin('reaction', 'delta')) {
+ $plugin->execute($vars);
+ }
+} \ No newline at end of file
diff --git a/delta_ui.admin.inc b/delta_ui.admin.inc
new file mode 100644
index 0000000..91c22ea
--- /dev/null
+++ b/delta_ui.admin.inc
@@ -0,0 +1,463 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Delta UI functionality
+ *
+ * ===============================
+ * ==== ========= ==============
+ * ==== ========= ==============
+ * ==== ========= === =========
+ * ==== === === == === ==
+ * == == = == === === = =
+ * = = == == === ====== =
+ * = = == ===== === ==== =
+ * = = == = == === === = =
+ * == === === === === =
+ * ===============================
+ *
+ */
+
+/**
+ * Menu callback; displays the delta listing page.
+ */
+function delta_theme_settings_config($form, &$form_state) {
+ drupal_set_title(t('Delta Theme Settings'));
+ $form['delta'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Delta Theme API Settings & Configuration'),
+ '#description' => t('In these default settings for <a href="http://himer.us/delta-module">Delta</a>, you can select which active themes will use contextual theme settings. Only enabled themes are listed here.'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ // get active themes for the settings form
+ $filter_themes = FALSE;
+ $themes = delta_get_themes_form_array($filter_themes);
+ // create checkboxes to select themes that may be manipulated
+ $form['delta']['delta_themes'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Themes to manipulate'),
+ '#options' => $themes,
+ '#default_value' => variable_get('delta_themes', array()),
+ '#description' => t('Here you may select the themes that should be manipulated using this Delta Theme API. Only themes that are enabled will be listed. You can enable/disable themes via the <a href="'. base_path() .'admin/appearance">Theme Administration</a> page.'),
+ );
+ return system_settings_form($form);
+}
+
+
+/**
+ * Menu callback;
+ */
+function delta_templates_view($theme_name = FALSE) {
+ drupal_set_title(t('Delta Templates'));
+ return render(drupal_get_form('delta_templates_list', $theme_name));
+}
+
+/**
+ * Menu callback; displays the delta listing page.
+ */
+function delta_templates_list($form, &$form_state) {
+ $form = array();
+ $form['delta'] = array(
+ '#type' => 'vertical_tabs',
+ '#weight' => 10,
+ );
+ $themes = delta_get_themes_array();
+ foreach($themes AS $info) {
+ // create fieldset for each theme we have the ability to manipulate
+ $form['delta'][$info->name] = array(
+ '#type' => 'fieldset',
+ '#title' => t($info->info['name']),
+ );
+ // build the data for each theme, and it's theme settings templates
+ $form['delta'][$info->name]['content'] = delta_get_templates($info->name);
+ }
+ return $form;
+}
+
+/**
+ * delta_get_templates function.
+ *
+ * @access public
+ * @param mixed $theme. (default: FALSE)
+ * @return void
+ * @todo Make the SQL SELECT statement conform to the PDO
+ */
+function delta_get_templates($theme = FALSE) {
+ if (isset($theme)) {
+ $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => '3'));
+ $rows = array();
+ $sql = "
+ SELECT dt.name, dt.system_name, dt.tid
+ FROM {delta_theme_settings} dt
+ WHERE dt.theme = :theme
+ ORDER BY dt.name ASC";
+ $result = db_query($sql, array(':theme' => $theme), array('fetch' => PDO::FETCH_ASSOC));
+ foreach ($result as $item) {
+ $row = array(
+ 'name' => '<h3>' . $item['name'] . '</h3><span class="description"><strong>' . t('Machine Name: ') . '</strong><em>' . $item['system_name'] . '</em></span>',
+ 'edit' => l(t('Edit'), 'admin/appearance/delta/templates/edit/' . $item['system_name']),
+ 'configure' => l(t('Configure'), 'admin/appearance/delta/templates/configure/' . $item['system_name']),
+ 'delete' => l(t('Delete'), 'admin/appearance/delta/templates/delete/' . $item['system_name']),
+ );
+ $rows[] = $row;
+ }
+ $build['table'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ '#empty' => t('No theme settings templates available. <a href="@link">Add template</a>.', array('@link' => url('admin/appearance/delta/templates/add'))),
+ );
+ return $build;
+ }
+ return FALSE;
+}
+
+
+
+
+/**
+ * delta_get_template_data function.
+ *
+ * @access public
+ * @param mixed $template
+ * @return void
+ * @todo Make the SQL SELECT statement conform to the PDO
+ */
+function delta_get_template_data($template) {
+ $sql = "
+ SELECT dt.name, dt.system_name, dt.tid, dt.data, dt.theme
+ FROM {delta_theme_settings} dt
+ WHERE dt.system_name = :template
+ LIMIT 1";
+ $result = db_query($sql, array(':template' => $template), array('fetch' => PDO::FETCH_ASSOC));
+ foreach ($result as $item) {
+ $data = $item;
+ }
+ return $data;
+}
+
+/**
+ * Form callback for creating and editing theme settings templates
+ *
+ * @param $form
+ * @param $form_state
+ */
+
+function delta_template_edit($form, &$form_state, $template = FALSE) {
+ if($template) {
+ //drupal_set_message('we are editing <strong>' . $template . '</strong>.');
+ $data = delta_get_template_data($template);
+ }
+ $form = array();
+
+
+ if(isset($form_state['build_info']['args'][0])) {
+ drupal_set_title(t('Edit Delta Template'));
+ $edit = $form_state['build_info']['args'][0];
+ }
+ else {
+ drupal_set_title(t('Add Delta Template'));
+ }
+
+ $form['delta'] = array(
+ '#type' => 'vertical_tabs',
+ '#weight' => -100,
+ '#prefix' => '',
+ '#suffix' => '<div id="theme_settings_replace"></div>',
+ );
+ $form['delta']['settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Default Settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ $form['delta']['settings']['tid'] = array(
+ '#type' => 'value',
+ '#value' => isset($data['tid']) ? $data['tid'] : NULL,
+ );
+ $form['delta']['settings']['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of Template'),
+ '#required' => TRUE,
+ '#size' => 32,
+ '#default_value' => isset($data['name']) ? $data['name'] : NULL,
+ );
+ $form['delta']['settings']['name'] = array(
+ '#type' => 'machine_name',
+ '#title' => t('System name'),
+ '#default_value' => isset($data['system_name']) ? $data['system_name'] : NULL,
+ '#maxlength' => 64,
+ '#description' => t('A unique name to construct the URL for the template. It must only contain lowercase letters, numbers and hyphens.'),
+ '#machine_name' => array(
+ 'exists' => 'delta_template_name_exists',
+ 'source' => array('delta', 'settings', 'title'),
+ 'label' => t('System Name'),
+ 'replace_pattern' => '[^a-z0-9-]+',
+ 'replace' => '-',
+ ),
+ '#disabled' => isset($data['tid']) ? TRUE : FALSE,
+ );
+ $allowed_themes = variable_get('delta_themes', array());
+ $themes = delta_get_themes_form_array($allowed_themes);
+ $form['delta']['settings']['theme'] = array(
+ '#type' => 'select',
+ '#title' => t('Theme'),
+ '#default_value' => isset($data['theme']) ? $data['theme'] : NULL,
+ '#options' => array('none' => 'Select Theme') + $themes,
+ /*
+ '#ajax' => array(
+ 'callback' => 'delta_load_theme_settings_callback',
+ 'wrapper' => 'theme_settings_replace',
+ 'method' => 'replace',
+ 'effect' => 'fade',
+ ), */
+ // disable changing the theme this is associated with after creation
+ // you would need to create a new one to do something like that. :P
+ '#disabled' => isset($data['tid']) ? TRUE : FALSE,
+ );
+ /*
+ $form['delta']['overrides'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Theme Settings Overrides'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ if (isset($data['theme'])) {
+ $form['delta']['overrides']['custom'] = delta_load_theme_settings_callback($form, $form_state, $data['theme']);
+ }
+ */
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ );
+ // Only custom theme setting templates may be deleted.
+ /*
+ $form['actions']['delete'] = array(
+ '#type' => 'submit',
+ '#value' => t('Delete'),
+ //'#access' => isset($edit) ? TRUE : FALSE,
+ );
+ */
+ //krumo($form);
+ return $form;
+}
+
+/**
+ * delta_template_configure function.
+ *
+ * @access public
+ * @param mixed $form
+ * @param mixed &$form_state
+ * @param mixed $template. (default: FALSE)
+ * @return void
+ */
+function delta_template_configure($form, &$form_state, $template = FALSE) {
+ if($template) {
+ $data = delta_get_template_data($template);
+ drupal_set_title(t('Editing '. $data['name']));
+ }
+ if (isset($data['theme'])) {
+
+ $form = delta_load_theme_settings_callback($data['theme'], $template);
+
+ $form['#submit'] = array('delta_ui_template_configure_submit');
+ $form['#validate'] = array('delta_ui_template_configure_validate');
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save Template'),
+ );
+ return $form;
+ }
+ return 'Error Loading Theme Settings form...';
+}
+
+
+/**
+ * delta_template_configure function.
+ *
+ * @access public
+ * @param mixed $form
+ * @param mixed &$form_state
+ * @param mixed $template. (default: FALSE)
+ * @return void
+ */
+function delta_template_delete($form, &$form_state, $template = FALSE) {
+ if($template) {
+ $data = delta_get_template_data($template);
+ drupal_set_title(t('Deleting '. $data['name']));
+ }
+ if (isset($data['theme'])) {
+
+ $form = array();
+ $form['tid'] = array(
+ '#type' => 'value',
+ '#value' => isset($data['tid']) ? $data['tid'] : NULL,
+ );
+ $form['template_delete'] = array(
+ '#markup' => '<p><strong>WARNING:</strong> Deleting this theme settings template will immediately make it unavailable.</p>',
+ );
+ $form['#submit'] = array('delta_ui_template_delete_submit');
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Delete Template'),
+ );
+ return $form;
+ }
+ return 'Error Loading Theme Settings form...';
+}
+
+
+function delta_load_theme_settings_callback($theme, $template) {
+ if ($theme != 'none') {
+ $key = $theme;
+ $var = 'theme_delta_' . $template . '_settings';
+ $themes = system_rebuild_theme_data();
+ $features = $themes[$key]->info['features'];
+ $form = array();
+ $form_state['build_info']['args'][0] = $key;
+ // Call engine-specific settings.
+ $function = $themes[$key]->prefix . '_engine_settings';
+ if (function_exists($function)) {
+ $form['engine_specific'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Theme-engine-specific settings'),
+ '#description' => t('These settings only exist for the themes based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)),
+ );
+ $function($form, $form_state);
+ }
+ // create the variable we will store the data in.
+ $form['var'] = $form['delta_template'] = array('#type' => 'hidden', '#value' => $var);
+ // Create a list which includes the current theme and all its base themes.
+ if (isset($themes[$key]->base_themes)) {
+ $theme_keys = array_keys($themes[$key]->base_themes);
+ $theme_keys[] = $key;
+ }
+ else {
+ $theme_keys = array($key);
+ }
+
+ // Save the name of the current theme (if any), so that we can temporarily
+ // override the current theme and allow theme_get_setting() to work
+ // without having to pass the theme name to it.
+ $default_theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : NULL;
+ $GLOBALS['theme_key'] = $key;
+
+ // Process the theme and all its base themes.
+ foreach ($theme_keys as $theme) {
+ // Include the theme-settings.php file.
+ $filename = DRUPAL_ROOT . '/' . str_replace("/$theme.info", '', $themes[$theme]->filename) . '/theme-settings.php';
+ if (file_exists($filename)) {
+ require_once $filename;
+ }
+
+ // Call theme-specific settings.
+ $function = $theme . '_form_system_theme_settings_alter';
+ if (function_exists($function)) {
+ $function($form, $form_state, $theme);
+ }
+ }
+
+ // Restore the original current theme.
+ if (isset($default_theme)) {
+ $GLOBALS['theme_key'] = $default_theme;
+ }
+ else {
+ unset($GLOBALS['theme_key']);
+ }
+ //krumo($form);
+ //$variable = variable_get('theme_delta_omega_starterkit_omega-starterkit-home-layout_settings');
+ //krumo($variable);
+
+ //module_load_include('inc', 'system', 'system.admin');
+ //$form = drupal_get_form('system_theme_settings', $theme);
+ return $form;
+ }
+ else {
+ return t('<div id="theme_settings_replace"><p>Unable to load theme settings form group... WTF...</p></div>');
+ }
+}
+
+
+/**
+ * Validation handler for delta_template_edit()
+ *
+ * This validation handler checks to ensure a theme has been selected.
+ *
+ * @param $form
+ * @param $form_state
+ */
+function delta_template_edit_validate($form, &$form_state) {
+ $values = $form_state['values'];
+ //dsm($values);
+ if ($values['theme'] == 'none') {
+ form_set_error('theme', t('You must select a theme in order to create a theme settings template. The settings stored are based on the default theme settings of the selected theme.'));
+ }
+}
+
+/**
+ * Submit handler for delta_template_edit()
+ *
+ * This submit handler will insert or update the database with the appropriate
+ * settings provided by the form submission.
+ *
+ * @param $form
+ * @param $form_state
+ */
+function delta_template_edit_submit($form, &$form_state) {
+ $values = $form_state['values'];
+ $item = array(
+ 'tid' => isset($values['tid']) ? $values['tid'] : FALSE,
+ 'name' => check_plain($values['title']),
+ 'system_name' => check_plain($values['name']),
+ 'theme' => check_plain($values['theme']),
+ 'data' => array(),
+ );
+ // save record
+ if ($item['tid']) {
+ drupal_write_record('delta_theme_settings', $item, 'tid');
+ }
+ else {
+ drupal_write_record('delta_theme_settings', $item);
+ }
+
+ drupal_set_message('The custom theme settings template <strong>' . $item['name'] . '</strong> has been saved for <em>'. $item['theme'] .'</em>...');
+ drupal_set_message('You may now configure the <strong>' . $item['name'] . '</strong> theme settings template.');
+ drupal_goto('admin/appearance/delta/templates/configure/'. $item['system_name']);
+}
+
+/**
+ * Helper function for machine readable names in {delta_theme_settings}
+ * @param $t
+ */
+function delta_template_name_exists($t) {
+ $exists = db_query_range('SELECT 1 FROM {delta_theme_settings} WHERE system_name = :name', 0, 1, array(':name' => $t))->fetchField();
+ return $exists;
+}
+
+/**
+ * Menu callback; displays the delta listing page.
+ */
+function delta_overrides_list($form, &$form_state) {
+ drupal_set_title(t('Delta Overrides'));
+ //krumo($form_state);
+ $theme = isset($form_state['build_info']['args'][0]) ? $form_state['build_info']['args'][0] : FALSE;
+ $themes = list_themes();
+ //krumo($themes);
+ if($theme) {
+ drupal_set_title(t('Delta Overrides for ' . $themes[$theme]->info['name']));
+ }
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ );
+ return $form;
+} \ No newline at end of file
diff --git a/delta_ui.info b/delta_ui.info
new file mode 100644
index 0000000..5ac304e
--- /dev/null
+++ b/delta_ui.info
@@ -0,0 +1,10 @@
+; $Id$
+name = Delta UI
+description = The Delta UI provides a user interface to build and edit the contextual theme settings provided by the Delta module.
+package = Theme Tools
+core = 7.x
+
+dependencies[] = delta
+
+files[] = delta_ui.module
+scripts[] = detla_ui.js \ No newline at end of file
diff --git a/delta_ui.js b/delta_ui.js
new file mode 100644
index 0000000..28c006f
--- /dev/null
+++ b/delta_ui.js
@@ -0,0 +1,6 @@
+// $Id$
+(function ($) {
+ $(document).ready(function(){
+ //Drupal.settings.machineName = $('.edit-system-name');
+ });
+})(jQuery);
diff --git a/delta_ui.module b/delta_ui.module
new file mode 100644
index 0000000..8d34e0a
--- /dev/null
+++ b/delta_ui.module
@@ -0,0 +1,227 @@
+<?php
+/**
+ * Implementation of hook_menu().
+ */
+
+/**
+ * Implementation of hook_permission().
+ */
+function delta_ui_permission() {
+ return array(
+ 'administer delta' => array(
+ 'title' => t('Administer Delta'),
+ 'description' => t('Administer settings for the Delta module.'),
+ ),
+ );
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function delta_ui_menu() {
+ $items['admin/appearance/delta'] = array(
+ 'title' => 'Delta',
+ 'description' => 'Manage your delta settings and rules, import and export delta settings for each theme',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('delta_theme_settings_config'),
+ 'access arguments' => array('administer delta'),
+ 'file' => 'delta_ui.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ );
+ $items['admin/appearance/delta/settings'] = array(
+ 'title' => 'Settings',
+ 'description' => 'Manage Delta settings.',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'parent' => 'admin/appearance/delta',
+ 'weight' => -10,
+ );
+
+
+ $items['admin/appearance/delta/templates'] = array(
+ 'title' => 'Templates',
+ 'description' => 'Manage theme setting templates.',
+ 'page callback' => 'delta_templates_view',
+ 'access arguments' => array('administer delta'),
+ 'file' => 'delta_ui.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ 'parent' => 'admin/appearance/delta',
+ );
+ $items['admin/appearance/delta/templates/list'] = array(
+ 'title' => 'List',
+ 'description' => 'Manage your theme setting templates.',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'parent' => 'admin/appearance/delta/templates',
+ 'weight' => -1,
+ );
+
+ $items['admin/appearance/delta/templates/add'] = array(
+ 'title' => 'Add Template',
+ 'description' => 'Create a new theme setting template.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('delta_template_edit'),
+ 'access arguments' => array('administer delta'),
+ 'file' => 'delta_ui.admin.inc',
+ 'type' => MENU_LOCAL_ACTION,
+ 'parent' => 'admin/appearance/delta/templates',
+ );
+
+ $items['admin/appearance/delta/templates/edit/%'] = array(
+ 'title' => 'Edit',
+ 'description' => 'Edit a Theme Settings Template.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('delta_template_edit', 5),
+ 'access arguments' => array('administer delta'),
+ 'file' => 'delta_ui.admin.inc',
+ 'type' => MENU_NORMAL_ITEM,
+ 'tab_parent' => 'admin/appearance/delta/templates',
+ );
+
+ $items['admin/appearance/delta/templates/configure/%'] = array(
+ 'title' => 'Settings',
+ 'description' => 'Override settings for Template.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('delta_template_configure', 5),
+ 'access arguments' => array('administer delta'),
+ 'file' => 'delta_ui.admin.inc',
+ 'type' => MENU_NORMAL_ITEM,
+ 'tab_parent' => 'admin/appearance/delta/templates',
+ );
+ $items['admin/appearance/delta/templates/delete/%'] = array(
+ 'title' => 'Delete',
+ 'description' => 'Delete Theme Settings Template.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('delta_template_delete', 5),
+ 'access arguments' => array('administer delta'),
+ 'file' => 'delta_ui.admin.inc',
+ 'type' => MENU_NORMAL_ITEM,
+ 'tab_parent' => 'admin/appearance/delta/templates',
+ );
+ return $items;
+}
+
+
+/**
+ * Pull data from actively selected themes
+ * @return the full theme array as normally pulled by list_themes(), but filters out the inactive themes.
+ */
+function delta_get_themes_array() {
+ $system_themes = list_themes();
+ $themes = array();
+ $configurable_themes = variable_get('delta_themes', array());
+ if (is_array($system_themes)) {
+ foreach ($system_themes AS $name => $theme) {
+ // let's gather active themes only, and the ones that have been set in Delta API global settings
+ if ($theme->status == 1 && isset($configurable_themes[$theme->name]) && $configurable_themes[$theme->name]) {
+ $themes[$name] = $theme;
+ }
+ }
+ return $themes;
+ }
+ return FALSE;
+}
+
+/**
+ * Pull data from actively selected themes
+ * @return a usable array of theme data for use in forms for checkboxes or radio buttons
+ */
+function delta_get_themes_form_array(&$filter) {
+ $system_themes = list_themes();
+ $configurable_themes = variable_get('delta_themes', array());
+ $themes = array();
+ if (is_array($system_themes)) {
+ foreach ($system_themes AS $name => $theme) {
+ // let's gather active themes only
+ if (!$filter) {
+ if ($theme->status == 1) {
+ $themes[$name] = $theme->info['name'];
+ }
+ }
+ else {
+ if ($theme->status == 1 && isset($configurable_themes[$theme->name]) && $configurable_themes[$theme->name]) {
+ $themes[$name] = $theme->info['name'];
+ }
+ }
+ }
+ return $themes;
+ }
+ return FALSE;
+}
+
+/**
+ * Called when saving the default delta settings form.
+ * This is needed to rebuild the menu when an update occurs in order to
+ * Add/Remove any themes that need to be in the menu system for rendering
+ * the appropriate sub-tabs.
+ */
+function delta_menu_rebuild() {
+ menu_rebuild();
+ menu_cache_clear_all();
+}
+
+
+/**
+ * Implmentation of hook_form_alter for delta_theme_settings_config()
+ * @return $form
+ * @see http://api.drupal.org/api/function/hook_form_FORM_ID_alter/6
+ * @see http://api.drupal.org/api/function/hook_form_alter/6
+ */
+function delta_form_delta_theme_settings_config_alter(&$form, &$form_state) {
+ // adding submit handler to rebuild the menu on submitting this form
+ $form['#submit'][] = 'delta_menu_rebuild';
+}
+
+function delta_ui_form_delta_template_configure_alter($form, &$form_state) {
+
+}
+
+function delta_ui_template_configure_submit($form, &$form_state) {
+ $values = $form_state['values'];
+ $values = $form_state['values'];
+ $key = $values['var'];
+
+ unset(
+ $values['var'],
+ $values['submit'],
+ $values['reset'],
+ $values['form_id'],
+ $values['op'],
+ $values['form_build_id'],
+ $values['form_token'],
+ $values['toggle_logo'],
+ $values['toggle_name'],
+ $values['toggle_slogan'],
+ $values['toggle_node_user_picture'],
+ $values['toggle_comment_user_picture'],
+ $values['toggle_comment_user_verification'],
+ $values['toggle_favicon'],
+ $values['toggle_main_menu'],
+ $values['toggle_secondary_menu'],
+ $values['default_logo'],
+ $values['logo_path'],
+ $values['logo_upload'],
+ $values['default_favicon'],
+ $values['favicon_path'],
+ $values['favicon_upload'],
+ $values['theme_settings_export_code']
+ );
+
+ variable_set($key, $values);
+ drupal_set_message(t('The configuration options have been saved.'));
+ cache_clear_all();
+}
+
+function delta_ui_template_delete_submit($form, &$form_state) {
+ $values = $form_state['values'];
+ $key = $values['tid'];
+ variable_del($key, $values);
+ db_delete('delta_theme_settings')
+ ->condition('tid', $key)
+ ->execute();
+ drupal_set_message(t('The item has been deleted.'));
+ cache_clear_all();
+ drupal_goto('admin/appearance/delta/templates');
+}
+
+function delta_ui_template_configure_validate($form, &$form_state) {
+
+} \ No newline at end of file
diff --git a/plugins/context_reaction_delta.inc b/plugins/context_reaction_delta.inc
new file mode 100644
index 0000000..8b4214f
--- /dev/null
+++ b/plugins/context_reaction_delta.inc
@@ -0,0 +1,53 @@
+<?php
+// $Id$
+
+/**
+ * Expose themes as context reactions.
+ */
+class context_reaction_delta extends context_reaction {
+ /**
+ * ugh
+ */
+ function options_form($context) {
+ $values = $this->fetch_from_context($context);
+ $form = array(
+ '#tree' => TRUE,
+ '#title' => t('Delta Override Template'),
+ );
+
+ $sql = "
+ SELECT dt.name, dt.system_name, dt.tid
+ FROM {delta_theme_settings} dt
+ ORDER BY dt.name ASC";
+ $result = db_query($sql, array(), array('fetch' => PDO::FETCH_ASSOC));
+ $options = array();
+ foreach ($result as $item) {
+ $options[$item['system_name']] = $item['name'];
+ }
+
+ $form['delta_template'] = array(
+ '#type' => 'radios',
+ '#title' => t('Select Custom theme settings template.'),
+ '#default_value' => isset($values['delta_template']) ? $values['delta_template'] : '',
+ '#options' => $options,
+ );
+ return $form;
+ }
+
+ /**
+ * Set 'section_title', and 'section_subtitle' if not set and merge all
+ * additional classes onto the 'body_classes'.
+ */
+ function execute(&$vars) {
+ $contexts = context_active_contexts();
+ foreach ($contexts as $context) {
+ if (!empty($context->reactions['delta'])) {
+ // add the delta override variable to the $vars so it can be used in omega_preprocess
+ $vars['delta'] = 'theme_delta_'.$context->reactions['delta']['delta_template'].'_settings';
+ // allow delta to load it's own custom form data, emulating a custom theme.
+ GLOBAL $delta_template;
+ $delta_template = isset($vars['delta']) ? $vars['delta'] : NULL;
+ }
+ }
+ }
+}