View source
<?php
function dynamic_background_panels_perm() {
return array(
'configure panels dynamic background',
);
}
function dynamic_background_panels_menu() {
$items = array();
$items['admin/build/backgrounds/panels'] = array(
'title' => 'Panels',
'description' => t('Configure dynamic background penels'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'dynamic_background_panels_admin_form',
),
'access arguments' => array(
'configure panels dynamic background',
),
'type' => MENU_LOCAL_TASK,
'weight' => -10,
);
return $items;
}
function dynamic_background_panels_admin_form() {
$form = array(
'#tree' => TRUE,
);
$form += dynamic_background_image_presents_form('dynamic_background_panels_imagecache');
$form += dynamic_background_css_behaviour_form('dynamic_background_panels_css');
return system_settings_form($form);
}
function dynamic_background_panels_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'panels_panel_context_edit_settings') {
drupal_add_css(drupal_get_path('module', 'dynamic_background_panels') . '/css/dynamic_background_panels.admin.css', 'module');
$form['conf']['dynamic_background'] = array(
'#type' => 'fieldset',
'#title' => t('Dynamic background'),
'#description' => t('To used this feature setup dynamic background and upload images.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$image_id = NULL;
if (isset($form_state['handler']->conf['dynamic_background'])) {
foreach ($form_state['handler']->conf['dynamic_background'] as $id => $value) {
if (isset($value['selected']) && $value['selected']) {
$image_id = $id;
break;
}
}
}
$form['conf']['dynamic_background'] += dynamic_background_image_selector_form($image_id);
$form['#submit'][] = 'dynamic_background_panels_conf_submit_handler';
}
}
function dynamic_background_panels_conf_submit_handler(&$form, &$form_state) {
$form_state['handler']->conf['dynamic_background'] = $form_state['values']['dynamic_background'];
}
function dynamic_background_panels_dynamic_background_css($vars) {
$image_id = NULL;
if ($pm_page = page_manager_get_current_page()) {
if (isset($pm_page['handler']->conf['dynamic_background'])) {
foreach ($pm_page['handler']->conf['dynamic_background'] as $id => $value) {
if ($value['selected']) {
$image_id = $id;
break;
}
}
}
}
$imagecache = variable_get('dynamic_background_panels_imagecache', FALSE);
if (!is_null($image_id)) {
$backgrounds = variable_get('dynamic_background_images', array());
if (isset($backgrounds[$image_id])) {
return array(
'image' => $backgrounds[$image_id]['default'],
'configuration' => variable_get('dynamic_background_panels_css', array()),
'imagecache' => $imagecache ? $imagecache['present'] : FALSE,
'weight' => 220,
);
}
}
}