You are here

class space_setting_logo in Spaces 6.2

Provides a logo setting for each space.

Hierarchy

Expanded class hierarchy of space_setting_logo

1 string reference to 'space_setting_logo'
spaces_design_spaces_settings in spaces_design/spaces_design.module
Implementation of hook_spaces_settings().

File

spaces_design/spaces_design.spaces.inc, line 6

View source
class space_setting_logo implements space_setting {
  var $id;
  function __construct($id = NULL) {
    $this->id = 'logo';
  }
  function form($space, $value = array()) {
    $form = array();
    $form['#title'] = t('Logo');
    $form['#description'] = t('Upload a logo image for this space. The image will be resized to better fit the design of this site.');
    if (!empty($value['fid'])) {
      $file = db_fetch_object(db_query('SELECT * FROM {files} f WHERE f.fid = %d', $value['fid']));
      if (!empty($file)) {
        $form['file'] = array(
          '#type' => 'value',
          '#value' => $file,
        );
        $form['display'] = array(
          '#type' => 'markup',
          '#value' => theme('imagecache', 'spaces-logo', $file->filepath),
        );
        $form['delete'] = array(
          '#type' => 'checkbox',
          '#title' => t('Delete current logo'),
        );
      }
    }
    $form['upload'] = array(
      '#type' => 'file',
      '#title' => t('Upload logo'),
      '#size' => 30,
      '#description' => t('Upload a new logo for this space.'),
      '#element_validate' => array(
        'spaces_design_upload_validate',
      ),
    );
    $form['fid'] = array(
      '#type' => 'value',
      '#value' => !empty($value['fid']) ? $value['fid'] : 0,
    );
    return $form;
  }
  function validate($space, $value) {
    return $value;
  }
  function submit($space, $value) {

    // Always clear out upload key -- not used
    unset($value['upload']);

    // Delete logo if specified
    if (!empty($value['delete']) && !empty($value['file'])) {
      file_delete($value['file']->filepath);
      db_query('DELETE FROM {files} WHERE fid = %d', $value['file']->fid);

      // Clear out fields
      if ($value['file']->fid == $value['fid']) {
        unset($value['fid']);
      }
      unset($value['delete']);
      unset($value['file']);
    }

    // Flush imagecache images
    if (!empty($value['fid'])) {
      $file = db_fetch_object(db_query('SELECT * FROM {files} f WHERE f.fid = %d', $value['fid']));
      if ($file) {
        imagecache_image_flush($file->filepath);
      }
    }
    else {
      unset($value['fid']);
    }
    return $value;
  }

}

Members