Esempio n. 1
0
 /**
  * Returns an un-used access key from the label given.
  *
  * @param string $label     The label to choose an access key from.
  * @param boolean $nocheck  Don't check if the access key already has been
  *                          used?
  *
  * @return string  A single lower case character access key or empty
  *                 string if none can be found
  */
 public static function getAccessKey($label, $nocheck = false, $shutdown = false)
 {
     /* Shutdown call for translators? */
     if ($shutdown) {
         if (!count(self::$_labels)) {
             return;
         }
         $script = basename($_SERVER['PHP_SELF']);
         $labels = array_keys(self::$_labels);
         sort($labels);
         $used = array_keys(self::$_used);
         sort($used);
         $remaining = str_replace($used, array(), 'abcdefghijklmnopqrstuvwxyz');
         self::log('Access key information for ' . $script);
         self::log('Used labels: ' . implode(',', $labels));
         self::log('Used keys: ' . implode('', $used));
         self::log('Free keys: ' . $remaining);
         return;
     }
     /* Use access keys at all? */
     if (!isset(self::$_noAccessKey)) {
         self::$_noAccessKey = !$GLOBALS['browser']->hasFeature('accesskey') || !$GLOBALS['prefs']->getValue('widget_accesskey');
     }
     if (self::$_noAccessKey || !preg_match('/_([A-Za-z])/', $label, $match)) {
         return '';
     }
     $key = $match[1];
     /* Has this key already been used? */
     if (isset(self::$_used[strtolower($key)]) && !($nocheck && isset(self::$_labels[$label]))) {
         return '';
     }
     /* Save key and label. */
     self::$_used[strtolower($key)] = true;
     self::$_labels[$label] = true;
     return $key;
 }