You are here

public function sweaver_plugin_images::sweaver_menu_callback in Sweaver 7

Same name and namespace in other branches
  1. 6 plugins/sweaver_plugin_images/sweaver_plugin_images.inc \sweaver_plugin_images::sweaver_menu_callback()

Menu callback.

Overrides sweaver_plugin::sweaver_menu_callback

File

plugins/sweaver_plugin_images/sweaver_plugin_images.inc, line 148
Images plugin.

Class

sweaver_plugin_images
@file Images plugin.

Code

public function sweaver_menu_callback() {
  $form = array();
  $form['sweaver_plugin_images_tab'] = array(
    '#type' => 'checkbox',
    '#title' => t('Editor tab'),
    '#description' => t('Toggle this checkbox if you want to enable the images tab on the editor.'),
    '#default_value' => variable_get('sweaver_plugin_images_tab', TRUE),
  );

  // Use styles on images ?
  if (function_exists('image_styles')) {
    $form['sweaver_plugin_images_styles'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow to see styled version of images'),
      '#description' => t('Toggle this checkbox if you want to create styled versions of the images uploaded by the Image plugin.'),
      '#default_value' => variable_get('sweaver_plugin_images_styles', FALSE),
    );
  }
  else {
    $form['style_disabled'] = array(
      '#markup' => '<p>' . t('If you enable the image module, all images can be made available with all style variants.') . '</p>',
    );
    $form['sweaver_plugin_images_styles'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  $form['sweaver_plugin_handle_images'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('sweaver_plugin_handle_images', 'sweaver_plugin_images'),
  );
  $form = system_settings_form($form);

  // Images list
  $rows = array();
  $output = '<p>' . l(t('Add new image'), 'admin/config/user-interface/sweaver/images/add') . '</p>';
  $query = 'SELECT ti.fid, ti.description, f.uri FROM {sweaver_image} ti
              INNER JOIN {file_managed} f on f.fid = ti.fid order by description ASC';
  $result = db_query($query)
    ->fetchAll();
  foreach ($result as $image) {
    $row = array();
    $row[] = check_plain($image->description);
    $operations = l(t('View'), file_create_url($image->uri)) . ' - ';
    $operations .= l(t('Edit'), 'admin/config/user-interface/sweaver/images/edit/' . $image->fid, array(
      'alias' => TRUE,
    )) . ' - ';
    $operations .= l(t('Delete'), 'admin/config/user-interface/sweaver/images/delete/' . $image->fid, array(
      'alias' => TRUE,
    ));
    $row[] = $operations;
    $rows[] = $row;
  }
  if (!empty($rows)) {

    // Output table.
    $header = array(
      t('Image'),
      t('Operations'),
    );
    $variables = array(
      'header' => $header,
      'rows' => $rows,
    );
    $output .= theme('table', $variables);
  }
  else {
    $output .= '<p>' . t('No images uploaded.') . '</p>';
  }
  $form['images_list'] = array(
    '#markup' => $output,
  );
  return $form;
}