Example #1
0
 public static function factory($args = array())
 {
     $locale = isset($args['locale']) ? $args['locale'] : null;
     if ($locale && Horde_String::lower($locale) != 'base') {
         $locale = str_replace(' ', '_', Horde_String::ucwords(str_replace('_', ' ', Horde_String::lower($locale))));
         $class = 'Horde_Support_Numerizer_Locale_' . $locale;
         if (class_exists($class)) {
             return new $class($args);
         }
         list($language, ) = explode('_', $locale);
         if ($language != $locale) {
             $class = 'Horde_Support_Numerizer_Locale_' . $language;
             if (class_exists($class)) {
                 return new $class($args);
             }
         }
     }
     return new Horde_Support_Numerizer_Locale_Base($args);
 }
Example #2
0
/**
 * Polish the $info global from create_table_info.  adds some
 * heuristic defaults.
 */
function enhance_info()
{
    global $info, $config;
    $title_field = field_get_title_field($info);
    for ($i = 0; $i < count($info); ++$i) {
        // per default text fields are searchable:
        switch (Horde_String::lower($info[$i]['type'])) {
            // String types
            case 'string':
            case 'char':
            case 'varchar':
            case 'blob':
            case 'tinyblob':
            case 'tinytext':
            case 'mediumblob':
            case 'mediumtext':
            case 'longblob':
            case 'longtext':
                $info[$i]['search'] = 1;
                break;
            default:
                $info[$i]['search'] = 0;
        }
        // per default all non blob fields are displayed in list view
        if (is_blob($info[$i])) {
            $info[$i]['list'] = 0;
        } else {
            $info[$i]['list'] = 2;
        }
        // per default all fields are editable, except the primary_key
        // and timestamp fields
        $pk = field_get_primary_key();
        if ($info[$i]['name'] == $pk['name'] || Horde_String::lower($info[$i]['type']) == 'timestamp') {
            $info[$i]['edit'] = 0;
        } else {
            $info[$i]['edit'] = 1;
        }
        $info[$i]['view'] = 1;
        // view everything
        // Field description (displayed to user). Defaults to name.
        // Please note that underscores here result in hotkeys.
        $info[$i]['desc'] = Horde_String::ucwords($info[$i]['name']);
        // Set the flag for the title field.
        if ($info[$i]['name'] == $title_field['name']) {
            $info[$i]['flags'] .= ' title';
        }
    }
}
Example #3
0
 /**
  * Transform a table name to a mapper class name.
  *
  * @param string $table The database table name to look up.
  *
  * @return Horde_Rdo_Mapper A new Mapper instance if it exists, else null.
  */
 public function tableToMapper($table)
 {
     if (class_exists($class = Horde_String::ucwords($table) . 'Mapper')) {
         return new $class();
     }
     return null;
 }
Example #4
0
 public function componentFactory($component, $args = null)
 {
     $locale = isset($this->args['locale']) ? $this->args['locale'] : null;
     if ($locale && Horde_String::lower($locale) != 'base') {
         $locale = str_replace(' ', '_', Horde_String::ucwords(str_replace('_', ' ', Horde_String::lower($locale))));
         $class = 'Horde_Date_Parser_Locale_' . $locale . '_' . $component;
         if (class_exists($class)) {
             return new $class($args);
         }
         $language = array_shift(explode('_', $locale));
         if ($language != $locale) {
             $class = 'Horde_Date_Parser_Locale_' . $language . '_' . $component;
             if (class_exists($class)) {
                 return new $class($args);
             }
         }
     }
     $class = 'Horde_Date_Parser_Locale_Base_' . $component;
     return new $class($args);
 }
Example #5
0
 /**
  * Camel-cases a word.
  *
  * @todo Do we want locale-specific or locale-independent camel casing?
  *
  * @param string $word         The word to camel-case.
  * @param string $firstLetter  Whether to upper or lower case the first.
  *                             letter of each slash-separated section.
  *
  * @return string Camelized $word
  */
 public function camelize($word, $firstLetter = 'upper')
 {
     if ($camelized = $this->getCache($word, 'camelize' . $firstLetter)) {
         return $camelized;
     }
     $camelized = $word;
     if (Horde_String::lower($camelized) != $camelized && strpos($camelized, '_') !== false) {
         $camelized = str_replace('_', '/', $camelized);
     }
     if (strpos($camelized, '/') !== false) {
         $camelized = str_replace('/', '/ ', $camelized);
     }
     if (strpos($camelized, '_') !== false) {
         $camelized = strtr($camelized, '_', ' ');
     }
     $camelized = str_replace(' ', '', Horde_String::ucwords($camelized));
     if ($firstLetter == 'lower') {
         $parts = array();
         foreach (explode('/', $camelized) as $part) {
             $part[0] = Horde_String::lower($part[0]);
             $parts[] = $part;
         }
         $camelized = implode('/', $parts);
     }
     return $this->setCache($word, 'camelize' . $firstLetter, $camelized);
 }
Example #6
0
 /**
  *
  * @param $type
  * @param $tag
  * @param $intel
  * @param $data
  * @return unknown_type
  */
 protected function _formatData($type, $tag, $intel, $data)
 {
     switch ($type) {
         case 'ASCII':
             // Search for a null byte and stop there.
             if (($pos = strpos($data, chr(0))) !== false) {
                 $data = substr($data, 0, $pos);
             }
             // Format certain kinds of strings nicely (Camera make etc.)
             if ($tag == '010f') {
                 $data = Horde_String::ucwords(Horde_String::lower(trim($data)));
             }
             break;
         case 'URATIONAL':
         case 'SRATIONAL':
             $data = bin2hex($data);
             if ($intel == 1) {
                 $data = Horde_Image_Exif::intel2Moto($data);
             }
             if ($intel == 1) {
                 // intel stores them bottom-top
                 $top = hexdec(substr($data, 8, 8));
             } else {
                 // motorola stores them top-bottom
                 $top = hexdec(substr($data, 0, 8));
             }
             if ($intel == 1) {
                 // intel stores them bottom-top
                 $bottom = hexdec(substr($data, 0, 8));
             } else {
                 // motorola stores them top-bottom
                 $bottom = hexdec(substr($data, 8, 8));
             }
             if ($type == 'SRATIONAL' && $top > 2147483647) {
                 // this makes the number signed instead of unsigned
                 $top = $top - 4294967296;
             }
             if ($bottom != 0) {
                 $data = $top / $bottom;
             } elseif ($top == 0) {
                 $data = 0;
             } else {
                 $data = $top . '/' . $bottom;
             }
             // Exposure Time
             if ($tag == '829a') {
                 if ($bottom != 0) {
                     $data = $top . '/' . $bottom;
                 } else {
                     $data = 0;
                 }
             }
             break;
         case 'USHORT':
         case 'SSHORT':
         case 'ULONG':
         case 'SLONG':
         case 'FLOAT':
         case 'DOUBLE':
             $data = bin2hex($data);
             if ($intel == 1) {
                 $data = Horde_Image_Exif::intel2Moto($data);
             }
             if ($intel == 0 && ($type == 'USHORT' || $type == 'SSHORT')) {
                 $data = substr($data, 0, 4);
             }
             $data = hexdec($data);
             if ($type == 'SSHORT' && $data > 32767) {
                 // this makes the number signed instead of unsigned
                 $data = $data - 65536;
             }
             if ($type == 'SLONG' && $data > 2147483647) {
                 // this makes the number signed instead of unsigned
                 $data = $data - 4294967296;
             }
             break;
         case 'UNDEFINED':
             // ExifVersion,FlashPixVersion,InteroperabilityVersion
             if ($tag == '9000' || $tag == 'a000' || $tag == '0002') {
                 $data = sprintf(Horde_Image_Translation::t("version %d"), $data / 100);
             }
             break;
         default:
             $data = bin2hex($data);
             if ($intel == 1) {
                 $data = Horde_Image_Exif::intel2Moto($data);
             }
             break;
     }
     return $data;
 }