You are here

function tinybrowser_settings_form in TinyBrowser 7

1 string reference to 'tinybrowser_settings_form'
tinybrowser_admin in ./tinybrowser.module
Admin page

File

./tinybrowser.module, line 329

Code

function tinybrowser_settings_form($form, &$form_state) {
  $note = '';

  //------ Roles profiles ------
  $form['roles'] = array(
    '#tree' => TRUE,
  );
  $roles = tinybrowser_sorted_roles();
  $form['#weighted'] = count($roles) >= 2;
  foreach ($roles as $rid => $role) {
    $core = $rid == DRUPAL_AUTHENTICATED_RID;
    $form['roles'][$rid] = tinybrowser_role_form($role, $form['#weighted'], $core);
  }

  //------ WYSIWYG Editor ------
  $form['editor'] = array(
    '#type' => 'fieldset',
    '#title' => t('WYSIWYG editor'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  if (module_exists("tinytinymce")) {
    $default_editor = 'tinymce';
  }
  else {
    if (module_exists("fckeditor")) {
      $default_editor = 'fckeditor';
    }
    else {
      if (module_exists("ckeditor")) {
        $default_editor = 'ckeditor';
      }
      else {
        if (module_exists("wysiwyg")) {
          $install_dir = wysiwyg_get_path('');
          if (file_exists($install_dir . '/tinymce/jscripts/tiny_mce/tiny_mce.js')) {
            $default_editor = 'tinymce';
          }
          else {
            if (file_exists($install_dir . '/fckeditor/fckeditor.js')) {
              $default_editor = 'fckeditor';
            }
            else {
              if (file_exists($install_dir . '/ckeditor/ckeditor.js')) {
                $default_editor = 'ckeditor';
              }
              else {
                $default_editor = 'none';
              }
            }
          }
        }
        else {
          $default_editor = 'none';
        }
      }
    }
  }
  $editor = variable_get('tinybrowser_editor', $default_editor);
  $form['editor']['tinybrowser_editor'] = array(
    '#type' => 'select',
    '#title' => t('WYSIWYG editor to be used with '),
    '#default_value' => $editor,
    '#options' => array(
      'none' => t('None'),
      'tinymce' => t('TinyMCE'),
      'fckeditor' => t('FCKeditor'),
      'ckeditor' => t('CKEditor'),
    ),
  );

  //-------- tinymce --------
  if ($editor == 'tinymce') {
    $tinymce_root = tinybrowser_get_tinymce_root();
    if (!$tinymce_root) {

      // could not find TinyMCE
      $note .= t('TinyMCE is not installed properly with either TinyTinyMCE or Wysiwyg module. TinyBrowser requires either one of these module and TinyMCE installed properly.');
    }
    else {
      variable_set('tinybrowser_tinymce_root', $tinymce_root);
      $module = '';
      if (module_exists("tinytinymce")) {
        $module = 'TinyTinyMCE';
      }
      else {
        if (module_exists("wysiwyg")) {
          $module = 'Wysiwyg';
        }
        else {

          // could not find FCKeditor
          $note .= t('TinyMCE is not installed properly with either TinyTinyMCE or Wysiwyg module. TinyBrowser requires either one of these module and TinyMCE installed properly.');
        }
      }
      $editor_info = $module == '' ? '<p>' . t('Can find neither TinyTinyMCE module nor Wysiwyg module. Please make sure to enable either one of them.') . '</p>' : '<p>' . t('You are currently using TinyMCE with <b>!module</b> module.', array(
        '!module' => $module,
      )) . '</p>';
      $form['editor']['tinybrowser_editor_info'] = array(
        '#type' => 'item',
        '#markup' => $editor_info,
      );
      if ($module == 'TinyTinyMCE') {
        $init_script = variable_get('tinytinymce_advanced', '');
        if (!preg_match('/file_browser_callback\\s*:\\s*"tinyBrowser"/', $init_script)) {
          $note .= '<p>' . t('TinyTinyMCE module setting needs to be modified!  Please add the following line to the init script of the advanced mode of the TinyTinyMCE in order to use TinyBrowser with TinyMCE advanced mode.<br/><b>file_browser_callback: "tinyBrowser"</b>') . '</p>';
        }
      }
    }
  }
  else {
    if ($editor == 'fckeditor') {
      $tinymce_root = '';
      variable_set('tinybrowser_tinymce_root', $tinymce_root);
      $module = '';
      if (module_exists("fckeditor")) {
        $module = 'FCKeditor';
      }
      else {
        if (module_exists("wysiwyg")) {
          $module = 'Wysiwyg';
        }
        else {

          // could not find FCKeditor
          $note .= t('FCKeditor is not installed properly with either FCKeditor module or Wysiwyg module. TinyBrowser requires either one of these module and FCKeditor installed properly.');
        }
      }
      $editor_info = $module == '' ? '<p>' . t('Can find neither FCKeditor module nor Wysiwyg module. Please make sure to enable either one of them.') . '</p>' : '<p>' . t('You are currently using FCKeditor with <b>!module</b> module.', array(
        '!module' => $module,
      )) . '</p>';
      $form['editor']['tinybrowser_editor_info'] = array(
        '#type' => 'item',
        '#markup' => $editor_info,
      );
    }
    else {
      if ($editor == 'ckeditor') {
        $tinymce_root = '';
        variable_set('tinybrowser_tinymce_root', $tinymce_root);
        $module = '';
        if (module_exists("ckeditor")) {
          $module = 'CKEditor';
        }
        else {
          if (module_exists("wysiwyg")) {
            $module = 'Wysiwyg';
          }
          else {

            // could not find CKEditor
            $note .= t('CKEditor is not installed properly with either CKEditor module or Wysiwyg module. TinyBrowser requires either one of these module and KCeditor installed properly.');
          }
        }
        $editor_info = $module == '' ? '<p>' . t('Can find neither CKEditor module nor Wysiwyg module. Please make sure to enable either one of them.') . '</p>' : '<p>' . t('You are currently using CKEditor with <b>!module</b> module.', array(
          '!module' => $module,
        )) . '</p>';
        $form['editor']['tinybrowser_editor_info'] = array(
          '#type' => 'item',
          '#markup' => $editor_info,
        );
      }
    }
  }
  unset($_SESSION['messages']['error']);

  // check if $cookie_domain is set or not
  if (!tinybrowser_requirements_check_cookie_domain()) {
    $note = '<p>' . t('TinyBrowser requires $cookie_domain to be set, but it is not set in your settings.php.') . '</p>';
  }
  if ($note) {
    drupal_set_message($note, 'error');
  }

  //------ Extensions ------
  $form['extensions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Extensions'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['extensions']['tinybrowser_ext_note'] = array(
    '#type' => 'item',
    '#markup' => '<p>' . t('Separate extensions with a space character and do not include leading dot. Extensions are case insensitive. Please use small letters for the extensions.') . '</p>',
  );
  $form['extensions']['tinybrowser_ok_ext_image'] = array(
    '#type' => 'textfield',
    '#title' => t('Permitted image file extensions'),
    '#default_value' => variable_get('tinybrowser_ok_ext_image', 'jpg jpeg gif png'),
    '#size' => 100,
    '#maxlength' => 120,
  );
  $form['extensions']['tinybrowser_ok_ext_media'] = array(
    '#type' => 'textfield',
    '#title' => t('Permitted media file extensions'),
    '#default_value' => variable_get('tinybrowser_ok_ext_media', 'swf dcr mov qt mpg mp3 mp4 mpeg avi wmv wm asf asx wmx wvx rm ra ram'),
    '#size' => 100,
    '#maxlength' => 120,
  );
  $form['extensions']['tinybrowser_prohibited_ext'] = array(
    '#type' => 'textfield',
    '#title' => t('Prohibited extensions'),
    '#default_value' => variable_get('tinybrowser_prohibited_ext', 'php php3 php4 phtml asp aspx ascx jsp cfm cfc pl bat exe dll reg cgi sh py asa asax config com inc'),
    '#size' => 100,
    '#maxlength' => 160,
    '#description' => t('These extensions are totally prohibited. You can not upload, edit and see it even if it\'s in the current folder. This setting has higher precedence over permitted extensions above. Most probably you do not want to change this. Any extensions other than these are permitted for the regular file operations.'),
  );

  //------ General ------
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['general']['tinybrowser_textarea'] = array(
    '#type' => 'textfield',
    '#title' => t('Enable inline image/file insertion into plain textareas'),
    '#default_value' => variable_get('tinybrowser_textarea', ''),
    '#maxlength' => NULL,
    '#description' => t('If you don\'t use any WYSIWYG editor, this feature will allow you to add your images or files as <strong>html code into any plain textarea</strong>. Enter <strong>comma separated textarea IDs</strong> under which you want to enable a link to TinyBrowser. Hint: ID of Body fields in most node types is edit-body.'),
  );
  $form['general']['tinybrowser_absolute_url'] = array(
    '#type' => 'checkbox',
    '#title' => t('Absolute URLs'),
    '#default_value' => variable_get('tinybrowser_absolute_url', 0),
    '#description' => t('If checked, absolute URLs including host name are returned instead of relative URL.'),
  );
  $form['general']['tinybrowser_upload_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Default behavior for existing files during file uploads'),
    '#options' => array(
      '1' => t('Replace the existing file with the new one'),
      '2' => t('Keep the existing file and rename the new one'),
      '3' => t('Keep the existing file and reject the new one'),
    ),
    '#default_value' => variable_get('tinybrowser_upload_mode', 1),
  );
  $form['general']['tinybrowser_thumbnail_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Thumbnail size'),
    '#size' => 10,
    '#maxlength' => 10,
    '#default_value' => variable_get('tinybrowser_thumbnail_size', 80),
    '#description' => '<p>' . t('If you change the thumbnail size, you need to flush all existing thumbnail images and regenerate them with a new size. Save the configuration first, then use the button below to do this.') . '</p>',
  );
  $form['general']['tinybrowser_flush_thumbnail'] = array(
    '#type' => 'submit',
    '#value' => t('Flush all thumbnails'),
    '#submit' => array(
      'tinybrowser_flush_all_thumbnails',
    ),
  );

  //------ Advanced ------
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['tinybrowser_default_view'] = array(
    '#type' => 'select',
    '#title' => t('Default view for the image browser'),
    '#default_value' => variable_get('tinybrowser_default_view', 'thumb'),
    '#options' => array(
      'thumb' => t('Thumbnail'),
      'detail' => t('Detail'),
    ),
  );
  $form['advanced']['tinybrowser_default_sort'] = array(
    '#type' => 'select',
    '#title' => t('Default sort mode'),
    '#default_value' => variable_get('tinybrowser_default_sort', 3),
    '#options' => array(
      0 => t('by name (acsending)'),
      1 => t('by name (descending)'),
      2 => t('by date (acsending)'),
      3 => t('by date (descending)'),
    ),
  );
  $form['advanced']['tinybrowser_pagination'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of files per page'),
    '#size' => 10,
    '#maxlength' => 10,
    '#default_value' => variable_get('tinybrowser_pagination', 0),
    '#description' => t('Specify the maximum number of files to be shown in a page of image browser and editor. Set 0 for no pagination.'),
  );
  $form['advanced']['tinybrowser_popup_window_size'] = array(
    '#type' => 'textfield',
    '#title' => t('TinyBrowser window size'),
    '#size' => 20,
    '#maxlength' => 20,
    '#field_suffix' => t('WIDTHxHEIGHT'),
    '#default_value' => variable_get('tinybrowser_popup_window_size', '770x480'),
    '#description' => t('Size of the TinyBrowser\'s popup window (default size: 770x480).'),
  );
  $form['advanced']['tinybrowser_max_crop_window_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum size of the image cropping window'),
    '#size' => 20,
    '#maxlength' => 20,
    '#field_suffix' => t('WIDTHxHEIGHT'),
    '#default_value' => variable_get('tinybrowser_max_crop_window_size', '1024x600'),
    '#description' => t('Maximum size of the TinyBrowser\'s image cropping window (default size: 1024x600). Please make this max size smaller than the screen size of your monitor.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['#theme'] = 'tinybrowser_admin';
  $form['#submit'][] = 'tinybrowser_admin_submit';
  return $form;
}