You are here

function _itweak_upload_install_imagecache_presets in iTweak Upload 6.2

2 calls to _itweak_upload_install_imagecache_presets()
itweak_upload_install in ./itweak_upload.install
Implementation of hook_install()
itweak_upload_update_6000 in ./itweak_upload.install
Implementation of hook_update_N()

File

./itweak_upload.install, line 26
Installation code for iTweakUpload.

Code

function _itweak_upload_install_imagecache_presets() {
  $ret = array();
  if (!module_exists('imagecache')) {
    $msg = t('Tried installing ImageCache preset for iTweak Upload module, but ImageCache module is not present. ImageCache presets for iTweak Upload module were not installed.');

    //    drupal_set_message($msg);
    $ret[] = array(
      'success' => FALSE,
      'query' => $msg,
    );
  }
  else {
    $imagecache_presets = array(
      array(
        'presetname' => 'AttachmentThumbnail',
      ),
    );
    $perms = array();
    foreach ($imagecache_presets as $preset) {
      $perms[] = 'view imagecache ' . $preset['presetname'];
    }

    // Add default permissions to new presets
    if (count($perms)) {

      // Which roles ids should be allowed to view the preset by default:
      $allow_roles = array(
        1,
        2,
      );

      // Get role names
      $result = db_query('SELECT r.rid, r.name FROM {role} r WHERE r.rid IN (%s)', implode(', ', $allow_roles));
      $roles = array();
      while ($role = db_fetch_object($result)) {
        $roles[$role->rid] = $role->name;
      }
      $perms = implode(', ', $perms);
      foreach ($roles as $rid => $role) {
        $res = _itweak_upload_add_permission($rid, $perms);
        if ($res['success']) {
          $res['query'] = t('Added permissions "%perms" to role %role.', array(
            '%perms' => $perms,
            '%role' => $role,
          ));
        }
        $ret[] = $res;
      }
    }
  }
  return $ret;
}