You are here

epub.admin.inc in Epub 6

Admin page callbacks for the book module.

File

epub.admin.inc
View source
<?php

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

/**
 * Returns an administrative overview of all ePubs.
 *
 * @return
 *   The html representation of the ePub admin section.
 */
function epub_admin_overview() {
  $result = db_query(db_rewrite_sql("SELECT * FROM {node} WHERE type = 'epub' ORDER BY title"));
  $headers = array(
    t('ePub'),
    t('Operations'),
    '',
    '',
  );
  $rows = array();
  while ($epub = db_fetch_object($result)) {
    $rows[] = array(
      l($epub->title, "node/{$epub->nid}"),
      l(t('Download'), "node/{$epub->nid}/epub"),
      l(t('Edit'), "node/{$epub->nid}/edit"),
      l(t('Delete'), "node/{$epub->nid}/delete"),
    );
  }
  return theme('table', $headers, $rows);
}

/**
 * Build and return the book settings form.
 *
 * @return
 *   The settings form structure.
 */
function epub_admin_settings() {
  $types = node_get_types('names');
  $form = array();
  $form['epub_custom_chapter_size'] = array(
    '#type' => 'textfield',
    '#size' => 10,
    '#maxlength' => 3,
    '#title' => t('Custom chapter size(in kB)'),
    '#description' => t('Set a custom maximum size for chapters of your ePubs. Keep in mind that the maximum allowed is 250kB.'),
    '#required' => TRUE,
    '#element_validate' => array(
      '_element_epub_custom_chapter_size_validate',
    ),
    '#default_value' => variable_get('epub_custom_chapter_size', 250),
  );
  return system_settings_form($form);
}

/**
 * Validator helper for admin settings form.
 *
 * Check chapter size field against a few rules and in case
 * set form error messages.
 *
 * @param $element
 *   An array containing form element structure.
 * @param &$form_state
 *   State of the form containing data inserted by the user.
 *
 * @return
 *   NULL.
 */
function _element_epub_custom_chapter_size_validate($element, &$form_state) {
  $value = isset($form_state['values']['epub_custom_chapter_size']) ? $form_state['values']['epub_custom_chapter_size'] : NULL;
  if (!is_numeric($value)) {
    form_set_error('epub_custom_chapter_size', t('Please enter a number between 1 and 250'));
    return;
  }
  if ($value < 1) {
    form_set_error('epub_custom_chapter_size', t("Chapter size can' t be less than 1 kB"));
    return;
  }
  if ($value > 250) {
    form_set_error('epub_custom_chapter_size', t("Chapter size can' t exceed 250 kB"));
    return;
  }
}

Functions

Namesort descending Description
epub_admin_overview Returns an administrative overview of all ePubs.
epub_admin_settings Build and return the book settings form.
_element_epub_custom_chapter_size_validate Validator helper for admin settings form.