first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,239 @@
<?php
/**
* @todo
*/
function omega_tools_theme_reset_confirm($form, &$form_state, $theme) {
$themes = list_themes();
$form_state['theme'] = $theme;
return confirm_form($form,
t('Are you sure you want to reset the theme %name?', array('%name' => $themes[$theme]->info['name'])),
'admin/appearance/settings/' . $theme,
t('<p>You are about to purge the theme settings stored in the database for this theme.</p><p>This will revert to whatever information is set in the .info file, and erase any un-exported customizations.</p>'),
t('Reset'),
t('Cancel')
);
}
/**
* @todo
*/
function omega_tools_theme_reset_confirm_submit($form, &$form_state) {
$themes = list_themes();
$theme = $form_state['theme'];
omega_tools_revert_theme_settings($theme);
$form_state['redirect'] = 'admin/appearance/settings/' . $theme;
}
/**
* @todo
*/
function omega_tools_theme_download($subtheme) {
file_download('temporary', file_uri_target(omega_tools_write_archive(drupal_get_path('theme', $subtheme), $subtheme)));
}
/**
* @todo
*/
function omega_tools_theme_export($form, &$form_state, $theme) {
$form_state['theme'] = $theme;
$info = drupal_parse_info_file(drupal_get_path('theme', $theme) . '/' . $theme . '.info');
$settings = isset($info['settings']) ? $info['settings'] : array();
$settings = variable_get('theme_' . $theme . '_settings', $settings);
$editable = _omega_tools_is_editable($theme);
$form['settings'] = array(
'#type' => 'textarea',
'#title' => t('Theme settings'),
'#description' => $editable ? t('You may now edit the theme settings before proceeding with the export and eventually saving them to the .info file of your theme. The theme settings provided in this form will be written into the .info file of the %name theme. All settings that are currently present in that file will be overwritten.', array('%name' => $info['name'])) : t("This theme is not editable and therefore you won't be able to export the theme settings automatically."),
'#default_value' => omega_tools_build_info_file($settings, 'settings'),
'#rows' => 30,
'#element_validate' => array('_omega_tools_validate_theme_settings'),
);
$form['revert'] = array(
'#type' => 'checkbox',
'#title' => t('Revert theme settings'),
'#description' => t('This will purge the theme settings from the database after exporting them to the .info file of this theme.'),
'#default_value' => TRUE,
'#access' => $editable,
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Export'),
'#access' => $editable,
);
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'admin/appearance/settings/' . $theme),
);
return $form;
}
/**
* @todo
*/
function omega_tools_theme_export_submit($form, &$form_state) {
$theme = $form_state['theme'];
$info = drupal_parse_info_file(drupal_get_path('theme', $theme) . '/' . $theme . '.info');
unset($info['settings']);
omega_tools_write_info_file($theme, array_merge($info, drupal_parse_info_format($form_state['values']['settings'])));
watchdog('theme', t('Theme settings for %theme exported and saved to .info file.', array('%theme' => $info['name'])));
drupal_set_message(t('The theme settings for %theme have been exported and saved to the corresponding .info file.', array('%theme' => $info['name'])));
if ($form_state['values']['revert']) {
omega_tools_revert_theme_settings($theme);
}
$form_state['redirect'] = 'admin/appearance/settings/' . $theme;
}
/**
* @todo
*/
function omega_tools_subtheme_add($form, &$form_state) {
system_rebuild_theme_data();
$themes = omega_tools_base_themes();
$starterkits = array();
if (!empty($themes)) {
$base = isset($form_state['values']['base']) ? $form_state['values']['base'] : 'omega';
$starterkits = omega_tools_starterkits($base);
$starter = isset($form_state['values']['starterkit']) ? $form_state['values']['starterkit'] : key($starterkits);
$starter = !empty($starter) ? $starter : '_none';
}
$form['info'] = array(
'#type' => 'fieldset',
'#title' => t('Theme information'),
);
$form['info']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('The human-readable name for this theme.'),
'#default_value' => isset($form_state['values']['name']) ? $form_state['values']['name'] : '',
'#size' => 30,
'#required' => TRUE,
);
$form['info']['machine_name'] = array(
'#type' => 'machine_name',
'#default_value' => isset($form_state['values']['machine_name']) ? $form_state['values']['machine_name'] : '',
'#maxlength' => 30,
'#machine_name' => array(
'source' => array('info', 'name'),
),
'#element_validate' => array('_omega_tools_validate_theme_name'),
);
$form['info']['automated'] = array(
'#type' => 'checkbox',
'#title' => t('Install automatically'),
'#description' => t('Please select wether you want to install this theme manually or if it should be automatically placed in the selected destination. This feature requires you to have write permission for the selected destination.'),
'#default_value' => TRUE,
'#element_validate' => array('omega_tools_subtheme_validate_automation'),
);
$form['info']['destination'] = array(
'#type' => 'select',
'#title' => t('Destination'),
'#description' => t('The theme will be place in the path selected here.'),
'#options' => omega_tools_sites_options(),
'#default_value' => 'all',
'#states' => array(
'visible' => array(
':input[name="automated"]' => array('checked' => TRUE),
),
),
);
$form['info']['base'] = array(
'#type' => 'select',
'#title' => t('Base theme'),
'#description' => t('The base theme for this theme.'),
'#options' => $themes,
'#default_value' => $base,
'#ajax' => array(
'callback' => '_omega_tools_starterkit_options_callback',
'wrapper' => 'starterkit-options-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['info']['starterkit_wrapper'] = array(
'#prefix' => '<div id="starterkit-options-wrapper">',
'#suffix' => '</div>',
);
$form['info']['starterkit_wrapper']['starterkit'] = array(
'#type' => 'radios',
'#title' => t('Starterkit'),
'#options' => array('_none' => t('Proceed without using a starterkit') . '<div class="description">' . t('This is not recommended.') . '</div>') + $starterkits,
'#description' => t('Starterkits simplify the process of creating new subthemes by providing a set of pre-defined files and settings. Choose wisely!'),
'#default_value' => $starter,
'#access' => !empty($starterkits),
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save and continue'),
);
return $form;
}
/**
* @todo
*/
function _omega_tools_starterkit_options_callback($form, $form_state) {
return $form['info']['starterkit_wrapper'];
}
/**
* @todo
*/
function omega_tools_subtheme_validate_automation($element, $form_state) {
$path = 'sites/' . $form_state['values']['destination'] . '/themes';
if ($element['#value'] == TRUE && !file_prepare_directory($path, NULL)) {
form_error($element, t('The destination that you selected is not writable. Please choose a different destination, or select the manual installation method.'));
}
}
/**
* @todo
*/
function omega_tools_subtheme_add_submit($form, &$form_state) {
$values = $form_state['values'];
$subtheme = new stdClass;
$subtheme->new = TRUE;
$subtheme->name = $values['name'];
$subtheme->machine_name = $values['machine_name'];
$subtheme->starterkit = isset($values['starterkit']) && $values['starterkit'] != '_none' ? $values['starterkit'] : NULL;
$subtheme->base = $values['base'];
$subtheme->status = FALSE;
$subtheme->default = FALSE;
$subtheme->automated = $values['automated'];
$subtheme->destination = $values['automated'] ? 'sites/' . $values['destination'] . '/themes/' . $subtheme->machine_name : NULL;
$subtheme->path = 'temporary://omega-tools/' . $subtheme->machine_name . '-' . substr(hash('sha256', serialize($subtheme) . microtime()), 0, 8);
if (omega_tools_subtheme_create($subtheme)) {
omega_tools_cache_set($subtheme->machine_name, $subtheme);
$form_state['redirect'] = 'admin/appearance/omega-tools/edit/' . $subtheme->machine_name;
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* Implements hook_drush_command().
*/
function omega_tools_drush_command() {
$items = array();
$items['omega-subtheme'] = array(
'description' => 'Create a Omega subtheme.',
'arguments' => array(
'name' => 'The name of your subtheme.',
),
'options' => array(
'destination' => 'The destination of your subtheme. Defaults to "all" (sites/all/themes).',
'machine_name' => 'The machine-readable name of your subtheme. This will be auto-generated from the human-readable name if ommited.',
'base' => 'The base theme that you want to build on. Defaults to "Omega" or the base theme of the starterkit (if provided).',
'starterkit' => 'The starterkit that your subtheme should use. It must have the same base theme as your subtheme. Defaults to "starterkit_omega_html5" if "--base" is not set either.',
'enable' => 'Automatically enable the subtheme after creation.',
'set-default' => 'Automatically enable the subtheme after creation and make it the default theme.',
),
'examples' => array(
'drush omega-subtheme "My Theme"' => 'Creates a Omega subtheme called "My Theme".',
'drush omega-subtheme "My Theme" --destination=example.com' => 'Creates a Omega subtheme called "My Theme" in sites/example.com/themes.',
'drush omega-subtheme "My Theme" --starterkit=starterkit_omega_html5' => 'Uses the HTML5 starterkit to create a Omega subtheme called "My Theme" in sites/all/themes (default).',
'drush omega-subtheme "My Theme" --base=alpha' => 'Creates a Alpha subtheme called "My Theme" without using a starterkit.',
),
);
return $items;
}
/**
* Implements of hook_drush_help().
*/
function omega_tools_drush_help($section) {
switch ($section) {
case 'drush:omega-subtheme':
return dt('This command will create a Omega subtheme.');
}
}
/**
* Implements of drush_hook_COMMAND_validate().
*/
function drush_omega_tools_omega_subtheme_validate($name) {
system_rebuild_theme_data();
$themes = list_themes();
$destination = drush_get_option('destination', 'all');
$machine_name = drush_get_option('machine_name', _omega_tools_transform_theme_name($name));
$base = drush_get_option('base');
$starterkit = drush_get_option('starterkit');
drush_set_option('machine_name', $machine_name);
if (!_omega_tools_theme_exists('alpha') || !_omega_tools_theme_exists('omega')) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('Where is the Omega base theme? I has not found it. :('));
}
if (!$machine_name || !preg_match('/^[a-z][a-z0-9_]*$/', $machine_name)) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('The machine name is invalid or could not be generated properly. It may only contain lowercase numbers, letters and underscores and must start with a letter. Please provide a proper machine name by using "--machine_name".'));
}
if (_omega_tools_theme_exists($machine_name)) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('A theme with that name already exists. The machine-readable name must be unique.'));
}
if (!in_array($destination, omega_tools_sites())) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('The destination is invalid.'));
}
if ($starterkit && (!_omega_tools_theme_exists($starterkit) || !_omega_tools_is_starterkit($starterkit))) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('There is no valid starterkit with the name !starterkit.', array('!starterkit' => $starterkit)));
}
if (!$base && $starterkit) {
$base = $themes[$starterkit]->info['base theme'];
drush_set_option('base', $base);
}
if ($base && !array_key_exists($base, omega_tools_base_themes())) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('There is no base theme with the name !base.', array('!base' => $base)));
}
if ($starterkit && $themes[$starterkit]->info['base theme'] != $base) {
return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('The base theme of the selected starterkit does not match the selected base theme.'));
}
if (!$base && !$starterkit) {
drush_set_option('base', 'omega');
drush_set_option('starterkit', 'starterkit_omega_html5');
}
else if (!$base) {
drush_set_option('base', 'omega');
}
}
/**
* Implements of drush_hook_COMMAND().
*/
function drush_omega_tools_omega_subtheme($name) {
$subtheme = new stdClass();
$subtheme->new = TRUE;
$subtheme->name = $name;
$subtheme->machine_name = drush_get_option('machine_name');
$subtheme->starterkit = drush_get_option('starterkit');
$subtheme->path = 'sites/' . drush_get_option('destination', 'all') . '/themes/' . $subtheme->machine_name;
$subtheme->base = drush_get_option('base');
$subtheme->default = drush_get_option('set-default') !== NULL;
$subtheme->status = $subtheme->default || drush_get_option('enable') !== NULL;
omega_tools_subtheme_create($subtheme);
omega_tools_subtheme_process($subtheme);
}

View File

@@ -0,0 +1,271 @@
<?php
/**
* @todo
*/
function omega_tools_subtheme_wizard($subtheme, $step = NULL) {
ctools_include('wizard');
$info = array(
'id' => 'omega_tools_subtheme_wizard',
'path' => 'admin/appearance/omega-tools/edit/' . $subtheme->machine_name . '/%step',
'free trail' => TRUE,
'show trail' => TRUE,
'show back' => TRUE,
'show cancel' => TRUE,
'show return' => FALSE,
'next text' => t('Continue'),
'next callback' => 'omega_tools_subtheme_wizard_next',
'finish callback' => 'omega_tools_subtheme_wizard_finish',
'cancel callback' => 'omega_tools_subtheme_wizard_cancel',
'finish text' => t('Finish'),
'order' => array(
'info' => t('Step 1: Theme information'),
'finalize' => t('Step 2: Finalize'),
),
'forms' => array(
'info' => array(
'form id' => 'omega_tools_subtheme_wizard_info_form',
),
'finalize' => array(
'form id' => 'omega_tools_subtheme_wizard_finalize_form',
),
'finished' => array(
'form id' => 'omega_tools_subtheme_wizard_finished_form',
),
),
);
$form_state = array('subtheme' => $subtheme);
return ctools_wizard_multistep_form($info, $step, $form_state);
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_cancel(&$form_state) {
$subtheme = &$form_state['subtheme'];
$form_state['redirect'] = 'admin/appearance';
omega_tools_cache_clear($subtheme->machine_name);
file_unmanaged_delete_recursive($subtheme->path);
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_next(&$form_state) {
omega_tools_cache_set($form_state['subtheme']->machine_name, $form_state['subtheme']);
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_finish(&$form_state) {
$subtheme = &$form_state['subtheme'];
if ($subtheme->automated) {
omega_tools_write_info_file($subtheme->machine_name, $subtheme->info, $subtheme->path);
omega_tools_cache_clear($subtheme->machine_name);
file_unmanaged_delete_recursive($subtheme->destination);
omega_tools_move($subtheme->path, $subtheme->destination);
if ((!$subtheme->status || !$subtheme->default) && variable_get('theme_default') == $subtheme->machine_name) {
$subtheme->default = FALSE;
theme_enable(array('bartik'));
variable_set('theme_default', 'bartik');
drupal_set_message(t('%name is now the default theme.', array('%name' => 'Bartik')));
}
omega_tools_subtheme_process($subtheme);
}
$form_state['redirect'] = $subtheme->automated ? 'admin/appearance' : 'admin/appearance/omega-tools/edit/' . $subtheme->machine_name . '/finished';
drupal_set_message(t('The configuration options have been saved.'));
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_info_form($form, &$form_state) {
$subtheme = &$form_state['subtheme'];
$form['info'] = array(
'#type' => 'fieldset',
'#title' => t('Theme information'),
);
$form['info']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('The human-readable name for this theme.'),
'#default_value' => isset($subtheme->info['name']) ? $subtheme->info['name'] : '',
'#size' => 30,
'#required' => TRUE,
);
$form['info']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('The description that will be shown on the theme listing page.'),
'#default_value' => isset($subtheme->info['description']) ? $subtheme->info['description'] : '',
);
$form['info']['version'] = array(
'#type' => 'textfield',
'#title' => t('Version'),
'#description' => t('The version of this theme.'),
'#default_value' => isset($subtheme->info['version']) ? $subtheme->info['version'] : '1.x',
);
$form['buttons']['next']['#next'] = $form_state['next'];
return $form;
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_info_form_submit($form, &$form_state) {
$values = &$form_state['values'];
$subtheme = &$form_state['subtheme'];
$subtheme->info['name'] = $values['name'];
$subtheme->info['description'] = $values['description'];
$subtheme->info['version'] = $values['version'];
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_finalize_form($form, &$form_state) {
$subtheme = &$form_state['subtheme'];
$form['finalize'] = array(
'#type' => 'fieldset',
'#title' => t('Finalize'),
);
$form['finalize']['description'] = array(
'#type' => 'item',
'#markup' => t('This is the final step for configuring your subtheme. You are now able to alter the final result by changing the <em>Advanced configuration</em>.'),
);
$form['finalize']['enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('Decide wether or not this theme should be enabled.'),
'#default_value' => $subtheme->status,
'#access' => $subtheme->automated,
);
$form['finalize']['default'] = array(
'#type' => 'checkbox',
'#title' => t('Default theme'),
'#description' => t('Decide wether or not you want this theme to be your default theme.'),
'#default_value' => $subtheme->default,
'#access' => $subtheme->automated,
'#states' => array(
'visible' => array(
':input[name="enable"]' => array('checked' => TRUE),
),
),
);
$form['finalize']['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced configuration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['finalize']['advanced']['manipulate'] = array(
'#type' => 'checkbox',
'#title' => t('Manipulate the content of %file', array('%file' => $subtheme->machine_name . '.info')),
'#description' => t('After enabling this option you are able to edit the textarea below.'),
'#default_value' => FALSE,
);
$form['finalize']['advanced']['info'] = array(
'#type' => 'textarea',
'#title' => t('Content of %file', array('%file' => $subtheme->machine_name . '.info')),
'#description' => t('Only change the content of this textarea if you know what you are doing.'),
'#default_value' => omega_tools_build_info_file($subtheme->info),
'#rows' => 20,
'#states' => array(
'enabled' => array(
':input[name="manipulate"]' => array('checked' => TRUE),
),
),
);
unset($form['buttons']['next']);
return $form;
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_finalize_form_submit($form, &$form_state) {
$values = $form_state['values'];
$subtheme = &$form_state['subtheme'];
$subtheme->info = $values['manipulate'] ? drupal_parse_info_format($values['info']) : $subtheme->info;
$subtheme->status = $values['enable'];
$subtheme->default = $values['enable'] && $values['default'];
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_finished_form($form, &$form_state) {
$subtheme = &$form_state['subtheme'];
drupal_set_title(t('Your subtheme is ready for download'));
unset($form['ctools_trail'], $form['buttons']['previous'], $form['buttons']['return']);
$form['buttons']['cancel']['#value'] = t('Finish');
$form['buttons']['next']['#value'] = t('Download');
$form['message']['#markup'] = t('Please press <strong>Download</strong> to save the theme to your local hard disk. After the download has completed you can either <strong>upload the contained folder manually</strong> or install it by using the <strong>Drupal Update Manager</strong>.');
$form['details'] = array(
'#type' => 'fieldset',
'#title' => t('Details'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['details']['info'] = array(
'#type' => 'textarea',
'#title' => t('Content of the .info file'),
'#default_value' => omega_tools_build_info_file($subtheme->info),
'#disabled' => TRUE,
'#rows' => 10,
);
return $form;
}
/**
* @todo
*/
function omega_tools_subtheme_wizard_finished_form_submit($form, &$form_state) {
$subtheme = &$form_state['subtheme'];
$temporary = 'temporary://omega-tools/' . $subtheme->name;
file_unmanaged_delete_recursive($temporary);
omega_tools_copy_recursive($subtheme->path, $temporary);
if ($download = omega_tools_write_archive($temporary, $subtheme->name)) {
file_transfer($download, omega_tools_file_download($download));
}
file_unmanaged_delete_recursive($temporary);
}