original_string: public static function add_type($extension, $mimetype, $coreicon,
              array $groups = array(), $corestring = '', $customdescription = '',
              $defaulticon = false) {
          // Check for blank extensions or incorrectly including the dot.
          $extension = (string)$extension;
          if ($extension === '' || $extension[0] === '.') {
              throw new coding_exception('Invalid extension .' . $extension);
          }
  
          // Check extension not already used.
          $mimetypes = get_mimetypes_array();
          if (array_key_exists($extension, $mimetypes)) {
              throw new coding_exception('Extension ' . $extension . ' already exists');
          }
  
          // For default icon, check there isn't already something with default icon
          // set for that MIME type.
          if ($defaulticon) {
              foreach ($mimetypes as $type) {
                  if ($type['type'] === $mimetype && !empty($type['defaulticon'])) {
                      throw new coding_exception('MIME type ' . $mimetype .
                              ' already has a default icon set');
                  }
              }
          }
  
          // Get existing custom filetype list.
          $customs = self::get_custom_types();
  
          // Check if there's a 'deleted' entry for the extension, if so then get
          // rid of it.
          foreach ($customs as $key => $custom) {
              if ($custom->extension === $extension) {
                  unset($customs[$key]);
              }
          }
  
          // Set up config record for new type.
          $newtype = self::create_config_record($extension, $mimetype, $coreicon, $groups,
                  $corestring, $customdescription, $defaulticon);
  
          // See if there's a default value with this extension.
          $needsadding = true;
          $defaults = self::get_default_types();
          if (array_key_exists($extension, $defaults)) {
              // If it has the same values, we don't need to add it.
              $defaultvalue = $defaults[$extension];
              $modified = (array)$newtype;
              unset($modified['extension']);
              ksort($defaultvalue);
              ksort($modified);
              if ($modified === $defaultvalue) {
                  $needsadding = false;
              }
          }
  
          // Add to array and set in config.
          if ($needsadding) {
              $customs[] = $newtype;
          }
          self::set_custom_types($customs);
      }
code: public static function add_type($extension, $mimetype, $coreicon,
              array $groups = array(), $corestring = '', $customdescription = '',
              $defaulticon = false) {
          // Check for blank extensions or incorrectly including the dot.
          $extension = (string)$extension;
          if ($extension === '' || $extension[0] === '.') {
              throw new coding_exception('Invalid extension .' . $extension);
          }
  
          // Check extension not already used.
          $mimetypes = get_mimetypes_array();
          if (array_key_exists($extension, $mimetypes)) {
              throw new coding_exception('Extension ' . $extension . ' already exists');
          }
  
          // For default icon, check there isn't already something with default icon
          // set for that MIME type.
          if ($defaulticon) {
              foreach ($mimetypes as $type) {
                  if ($type['type'] === $mimetype && !empty($type['defaulticon'])) {
                      throw new coding_exception('MIME type ' . $mimetype .
                              ' already has a default icon set');
                  }
              }
          }
  
          // Get existing custom filetype list.
          $customs = self::get_custom_types();
  
          // Check if there's a 'deleted' entry for the extension, if so then get
          // rid of it.
          foreach ($customs as $key => $custom) {
              if ($custom->extension === $extension) {
                  unset($customs[$key]);
              }
          }
  
          // Set up config record for new type.
          $newtype = self::create_config_record($extension, $mimetype, $coreicon, $groups,
                  $corestring, $customdescription, $defaulticon);
  
          // See if there's a default value with this extension.
          $needsadding = true;
          $defaults = self::get_default_types();
          if (array_key_exists($extension, $defaults)) {
              // If it has the same values, we don't need to add it.
              $defaultvalue = $defaults[$extension];
              $modified = (array)$newtype;
              unset($modified['extension']);
              ksort($defaultvalue);
              ksort($modified);
              if ($modified === $defaultvalue) {
                  $needsadding = false;
              }
          }
  
          // Add to array and set in config.
          if ($needsadding) {
              $customs[] = $newtype;
          }
          self::set_custom_types($customs);
      }
code_tokens: public static function add_type ( $ extension , $ mimetype , $ coreicon , array $ groups = array ( ) , $ corestring = '' , $ customdescription = '' , $ defaulticon = false ) { // Check for blank extensions or incorrectly including the dot. $ extension = ( string ) $ extension ; if ( $ extension === '' || $ extension [ 0 ] === '.' ) { throw new coding_exception ( 'Invalid extension .' . $ extension ) ; } // Check extension not already used. $ mimetypes = get_mimetypes_array ( ) ; if ( array_key_exists ( $ extension , $ mimetypes ) ) { throw new coding_exception ( 'Extension ' . $ extension . ' already exists' ) ; } // For default icon, check there isn't already something with default icon // set for that MIME type. if ( $ defaulticon ) { foreach ( $ mimetypes as $ type ) { if ( $ type [ 'type' ] === $ mimetype && ! empty ( $ type [ 'defaulticon' ] ) ) { throw new coding_exception ( 'MIME type ' . $ mimetype . ' already has a default icon set' ) ; } } } // Get existing custom filetype list. $ customs = self :: get_custom_types ( ) ; // Check if there's a 'deleted' entry for the extension, if so then get // rid of it. foreach ( $ customs as $ key => $ custom ) { if ( $ custom -> extension === $ extension ) { unset ( $ customs [ $ key ] ) ; } } // Set up config record for new type. $ newtype = self :: create_config_record ( $ extension , $ mimetype , $ coreicon , $ groups , $ corestring , $ customdescription , $ defaulticon ) ; // See if there's a default value with this extension. $ needsadding = true ; $ defaults = self :: get_default_types ( ) ; if ( array_key_exists ( $ extension , $ defaults ) ) { // If it has the same values, we don't need to add it. $ defaultvalue = $ defaults [ $ extension ] ; $ modified = ( array ) $ newtype ; unset ( $ modified [ 'extension' ] ) ; ksort ( $ defaultvalue ) ; ksort ( $ modified ) ; if ( $ modified === $ defaultvalue ) { $ needsadding = false ; } } // Add to array and set in config. if ( $ needsadding ) { $ customs [ ] = $ newtype ; } self :: set_custom_types ( $ customs ) ; }
docstring: Adds a new entry to the list of custom filetypes.
  
  @param string $extension File extension without dot, e.g. 'doc'
  @param string $mimetype MIME type e.g. 'application/msword'
  @param string $coreicon Core icon to use e.g. 'document'
  @param array $groups Array of group strings that this type belongs to
  @param string $corestring Custom lang string name in mimetypes.php
  @param string $customdescription Custom description (plain text/multilang)
  @param bool $defaulticon True if this should be the default icon for the type
  @throws coding_exception If the extension already exists, or otherwise invalid
docstring_tokens: Adds a new entry to the list of custom filetypes .