Exemplo n.º 1
0
/**
 * @return bool
 * @param module string, language string, key string, value string
 * @desc Returns true if new field label can be created, false otherwise.
 *       Probable reason for returning false: new_field_key already exists.
 */
function create_field_label($module, $language, $key, $value, $overwrite = false)
{
    $return_value = false;
    $mod_strings = return_module_language($language, $module);
    if (isset($mod_strings[$key]) && !$overwrite) {
        $GLOBALS['log']->info("Tried to create a key that already exists: {$key}");
    } else {
        $mod_strings = array_merge($mod_strings, array($key => $value));
        $dirname = "custom/modules/{$module}/language";
        $dir_exists = is_dir($dirname);
        if (!$dir_exists) {
            $dir_exists = create_module_lang_dir($module);
        }
        if ($dir_exists) {
            $filename = "{$dirname}/{$language}.lang.php";
            if (is_file($filename)) {
                $handle = sugar_fopen($filename, 'rb');
                $old_contents = fread($handle, filesize($filename));
                fclose($handle);
            } else {
                $old_contents = '';
            }
            $handle = sugar_fopen($filename, 'wb');
            if ($handle) {
                $contents = create_field_lang_pak_contents($old_contents, $key, $value, $language, $module);
                if (fwrite($handle, $contents)) {
                    $return_value = true;
                    $GLOBALS['log']->info("Successful write to: {$filename}");
                }
                fclose($handle);
            } else {
                $GLOBALS['log']->info("Unable to write edited language pak to file: {$filename}");
            }
        } else {
            $GLOBALS['log']->info("Unable to create dir: {$dirname}");
        }
    }
    return $return_value;
}
Exemplo n.º 2
0
/**
 * @return bool
 * @param module string, language string, key string, value string
 * @desc Returns true if new field label can be created, false otherwise.
 *       Probable reason for returning false: new_field_key already exists.
 */
function create_field_label($module, $language, $key, $value, $overwrite = false)
{
    $return_value = false;
    $mod_strings = return_module_language($language, $module);
    if (isset($mod_strings[$key]) && !$overwrite) {
        $GLOBALS['log']->info("Tried to create a key that already exists: {$key}");
    } else {
        $mod_strings = array_merge($mod_strings, array($key => $value));
        $dirname = "custom/modules/{$module}/language";
        if (SugarAutoLoader::ensureDir($dirname)) {
            $filename = "{$dirname}/{$language}.lang.php";
            if (is_file($filename) && filesize($filename) > 0) {
                $old_contents = file_get_contents($filename);
            } else {
                $old_contents = '';
            }
            $contents = create_field_lang_pak_contents($old_contents, $key, $value, $language, $module);
            if (!SugarAutoLoader::put($filename, $contents, true)) {
                $GLOBALS['log']->fatal("Unable to write edited language pak to file: {$filename}");
                return false;
            }
            return true;
        } else {
            $GLOBALS['log']->info("Unable to create dir: {$dirname}");
        }
    }
    return false;
}