You are here

content_theme.admin.inc in Content Theme 6

Same filename and directory in other branches
  1. 7.2 content_theme.admin.inc
  2. 7 content_theme.admin.inc

Admin page callbacks for the content_theme module.

File

content_theme.admin.inc
View source
<?php

/**
 * @file
 * Admin page callbacks for the content_theme module.
 */

/**
 * Menu callback; configures content node themes.
 */
function content_theme_admin_content_node() {
  $nodes = $nodes_select = array();
  $destination = drupal_get_destination();
  $sql_query = 'SELECT n.nid, n.title, nt.name AS type_name FROM {node} n LEFT JOIN {node_type} nt ON nt.type = n.type ORDER BY n.changed DESC';
  $sql_count = 'SELECT COUNT(nid) FROM {node}';
  $result = pager_query($sql_query, 50, 0, $sql_count);
  while ($node = db_fetch_object($result)) {
    $result_tmp = db_query('SELECT theme FROM {content_theme_node} WHERE nid = %d AND action = "edit"', $node->nid);
    $edit_theme = ($theme = db_fetch_object($result_tmp)) ? $theme->theme : '-content_type-';
    $result_tmp = db_query('SELECT theme FROM {content_theme_node} WHERE nid = %d AND action = "view"', $node->nid);
    $view_theme = ($theme = db_fetch_object($result_tmp)) ? $theme->theme : '-content_type-';
    $row = array();
    $row['node_title'] = array(
      '#value' => l(check_plain($node->title), 'node/' . $node->nid),
    );
    $row['node_type_name'] = array(
      '#value' => check_plain($node->type_name),
    );
    $row['node_theme_edit'] = array(
      '#value' => content_theme_get_theme_name($edit_theme),
    );
    $row['node_theme_view'] = array(
      '#value' => content_theme_get_theme_name($view_theme),
    );
    $row['op_edit'] = array(
      '#value' => l(t('edit'), 'node/' . $node->nid . '/edit', array(
        'query' => $destination,
      )),
    );
    $nodes[$node->nid] = $row;
    $nodes_select[$node->nid] = '';
  }
  $form = array();
  $form['update'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update content node themes'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['update']['content_theme_edit'] = array(
    '#type' => 'select',
    '#title' => t('Editing theme'),
    '#description' => t('Choose which theme the content creating and editing pages should display in. Content wide theme: %content_wide_theme; system default theme: %system_default_theme.', array(
      '%content_wide_theme' => content_theme_get_info_theme_name('content_wide', 'edit'),
      '%system_default_theme' => content_theme_get_info_theme_name(),
    )),
    '#default_value' => '-content_type-',
    '#options' => content_theme_get_content_node_options(),
  );
  $form['update']['content_theme_view'] = array(
    '#type' => 'select',
    '#title' => t('Viewing theme'),
    '#description' => t('Choose which theme the content viewing pages should display in. Content wide theme: %content_wide_theme; system default theme: %system_default_theme.', array(
      '%content_wide_theme' => content_theme_get_info_theme_name('content_wide', 'view'),
      '%system_default_theme' => content_theme_get_info_theme_name(),
    )),
    '#default_value' => '-content_type-',
    '#options' => content_theme_get_content_node_options(),
  );
  $form['update']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update themes'),
  );
  $form['nodes_select'] = array(
    '#type' => 'checkboxes',
    '#options' => $nodes_select,
  );
  $form['nodes'] = $nodes;
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}
function theme_content_theme_admin_content_node($form) {
  $rows = array();
  foreach (element_children($form['nodes']) as $nid) {
    $row = array();
    $row[] = drupal_render($form['nodes_select'][$nid]);
    $row[] = drupal_render($form['nodes'][$nid]['node_title']);
    $row[] = drupal_render($form['nodes'][$nid]['node_type_name']);
    $row[] = drupal_render($form['nodes'][$nid]['node_theme_edit']);
    $row[] = drupal_render($form['nodes'][$nid]['node_theme_view']);
    $row[] = drupal_render($form['nodes'][$nid]['op_edit']);
    $rows[] = array(
      'data' => $row,
    );
  }
  if (count($rows) > 0) {
    $header = array();
    $header[] = theme('table_select_header_cell');
    $header[] = t('Title');
    $header[] = t('Type');
    $header[] = t('Editing theme');
    $header[] = t('Viewing theme');
    $header[] = t('Operations');
    $output = drupal_render($form['update']);
    $output .= theme('table', $header, $rows);
    if (!is_null($form['pager']['#value'])) {
      $output .= drupal_render($form['pager']);
    }
    $output .= drupal_render($form);
  }
  else {
    $output = '<p>' . t('No content nodes available.') . '</p>';
  }
  return $output;
}
function content_theme_admin_content_node_validate($form, &$form_state) {
  $nodes_select = array_filter($form_state['values']['nodes_select']);
  if (count($nodes_select) == 0) {
    form_set_error('', t('No content nodes selected.'));
  }
}
function content_theme_admin_content_node_submit($form, &$form_state) {
  $edit_theme = $form_state['values']['content_theme_edit'];
  $view_theme = $form_state['values']['content_theme_view'];
  foreach ($form_state['values']['nodes_select'] as $node) {
    if (!empty($node)) {
      db_query('DELETE FROM {content_theme_node} WHERE nid = %d', $node);
      if ($edit_theme != '-content_type-') {
        db_query('INSERT INTO {content_theme_node} (nid, action, theme) VALUES (%d, "edit", "%s")', $node, $edit_theme);
      }
      if ($view_theme != '-content_type-') {
        db_query('INSERT INTO {content_theme_node} (nid, action, theme) VALUES (%d, "view", "%s")', $node, $view_theme);
      }
    }
  }
  drupal_set_message(t('The themes have been updated.'));
  cache_clear_all();
}

/**
 * Menu callback; configures content type themes.
 */
function content_theme_admin_content_type() {
  $types = $types_select = array();
  $destination = drupal_get_destination();
  $sql_query = 'SELECT type, name FROM {node_type} ORDER BY name, type';
  $sql_count = 'SELECT COUNT(type) FROM {node_type}';
  $result = pager_query($sql_query, 50, 0, $sql_count);
  while ($node_type = db_fetch_object($result)) {
    $edit_theme = variable_get('content_theme_content_type_edit_' . $node_type->type, '-content_wide-');
    $view_theme = variable_get('content_theme_content_type_view_' . $node_type->type, '-content_wide-');
    $row = array();
    $row['type_name'] = array(
      '#value' => check_plain($node_type->name),
    );
    $row['type_theme_edit'] = array(
      '#value' => content_theme_get_theme_name($edit_theme),
    );
    $row['type_theme_view'] = array(
      '#value' => content_theme_get_theme_name($view_theme),
    );
    $row['op_edit'] = array(
      '#value' => l(t('edit'), 'admin/content/node-type/' . $node_type->type, array(
        'query' => $destination,
      )),
    );
    $types[$node_type->type] = $row;
    $types_select[$node_type->type] = '';
  }
  $form = array();
  $form['update'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update content type themes'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['update']['content_theme_edit'] = array(
    '#type' => 'select',
    '#title' => t('Creating & editing theme'),
    '#description' => t('Choose which theme the content creating and editing pages should display in. Content wide theme: %content_wide_theme; system default theme: %system_default_theme.', array(
      '%content_wide_theme' => content_theme_get_info_theme_name('content_wide', 'edit'),
      '%system_default_theme' => content_theme_get_info_theme_name(),
    )),
    '#default_value' => '-content_wide-',
    '#options' => content_theme_get_content_type_options(),
  );
  $form['update']['content_theme_view'] = array(
    '#type' => 'select',
    '#title' => t('Viewing theme'),
    '#description' => t('Choose which theme the content viewing pages should display in. Content wide theme: %content_wide_theme; system default theme: %system_default_theme.', array(
      '%content_wide_theme' => content_theme_get_info_theme_name('content_wide', 'view'),
      '%system_default_theme' => content_theme_get_info_theme_name(),
    )),
    '#default_value' => '-content_wide-',
    '#options' => content_theme_get_content_type_options(),
  );
  $form['update']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update themes'),
  );
  $form['types_select'] = array(
    '#type' => 'checkboxes',
    '#options' => $types_select,
  );
  $form['types'] = $types;
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}
function theme_content_theme_admin_content_type($form) {
  $rows = array();
  foreach (element_children($form['types']) as $type) {
    $row = array();
    $row[] = drupal_render($form['types_select'][$type]);
    $row[] = drupal_render($form['types'][$type]['type_name']);
    $row[] = drupal_render($form['types'][$type]['type_theme_edit']);
    $row[] = drupal_render($form['types'][$type]['type_theme_view']);
    $row[] = drupal_render($form['types'][$type]['op_edit']);
    $rows[] = array(
      'data' => $row,
    );
  }
  if (count($rows) > 0) {
    $header = array();
    $header[] = theme('table_select_header_cell');
    $header[] = t('Type');
    $header[] = t('Creating & editing theme');
    $header[] = t('Viewing theme');
    $header[] = t('Operations');
    $output = drupal_render($form['update']);
    $output .= theme('table', $header, $rows);
    if (!is_null($form['pager']['#value'])) {
      $output .= drupal_render($form['pager']);
    }
    $output .= drupal_render($form);
  }
  else {
    $output = '<p>' . t('No content types available.') . '</p>';
  }
  return $output;
}
function content_theme_admin_content_type_validate($form, &$form_state) {
  $types_select = array_filter($form_state['values']['types_select']);
  if (count($types_select) == 0) {
    form_set_error('', t('No content types selected.'));
  }
}
function content_theme_admin_content_type_submit($form, &$form_state) {
  $edit_theme = $form_state['values']['content_theme_edit'];
  $view_theme = $form_state['values']['content_theme_view'];
  foreach ($form_state['values']['types_select'] as $type) {
    if (!empty($type)) {
      variable_set('content_theme_content_type_edit_' . $type, $edit_theme);
      variable_set('content_theme_content_type_view_' . $type, $view_theme);
    }
  }
  drupal_set_message(t('The themes have been updated.'));
}

/**
 * Menu callback; configures content wide themes.
 */
function content_theme_admin_content_wide() {
  $form = array();
  $form['update'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update content wide themes'),
  );
  $form['update']['content_theme_edit'] = array(
    '#type' => 'select',
    '#title' => t('Creating & editing theme'),
    '#description' => t('Choose which theme the content creating and editing pages should display in. System default theme: %system_default_theme.', array(
      '%system_default_theme' => content_theme_get_info_theme_name(),
    )),
    '#default_value' => variable_get('content_theme_content_wide_edit', '0'),
    '#options' => content_theme_get_content_wide_options(),
  );
  $form['update']['content_theme_view'] = array(
    '#type' => 'select',
    '#title' => t('Viewing theme'),
    '#description' => t('Choose which theme the content viewing pages should display in. System default theme: %system_default_theme.', array(
      '%system_default_theme' => content_theme_get_info_theme_name(),
    )),
    '#default_value' => variable_get('content_theme_content_wide_view', '0'),
    '#options' => content_theme_get_content_wide_options(),
  );
  $form['update']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update themes'),
  );
  return $form;
}
function content_theme_admin_content_wide_submit($form, &$form_state) {
  $edit_theme = $form_state['values']['content_theme_edit'];
  $view_theme = $form_state['values']['content_theme_view'];
  variable_set('content_theme_content_wide_edit', $edit_theme);
  variable_set('content_theme_content_wide_view', $view_theme);
  drupal_set_message(t('The themes have been updated.'));
}