In drupal7, how can i use varibles when exporting configuration using features and strongarm modules? - drupal-7

I am working on a drupal7 site.
In Dev, I have enabled and configured simplesamlphp_auth module.
I used features and strongarm to export the configuration to code.
The downloaded feature contain:
myfeature_sso.features.defaultconfig.inc
myfeature_sso.info
myfeature_sso.module
The .inc file contains the configuration values I had put in (admin/config/people/simplesamlphp_auth) correctly
Now, in a few places, I want to replace the hard coded values with variables that change based on the environment. I set the variables at the top of .inc file using variable_get $office_ou = variable_get('office_ou', NULL); ...and . A quick example is $base_url below:
$strongarm = new stdClass();
$strongarm->disabled = FALSE;
$strongarm->api_version = 1;
$strongarm->name = 'simplesamlphp_auth_logoutgotourl';
$strongarm->value = $base_url ;
$export['simplesamlphp_auth_logoutgotourl'] = $strongarm;
When I DPM these variables, they display correct values.
But on a fresh install when I enable myfeature_sso module the value of variables are missing.
missing value from $base_url variable
Can you please point me in the right direction?
Thank you.

I found the answer:
when in features ui, do not add fields relevant to simplesamle to the defaultconfig section. if you have any there remove them.
add fields relevant to simplesaml to storongarm section
export the feature
in your_feature_name.strongarm.inc add any additional php code to function your_feature_name_strongarm()
done

Related

Spring Annotations - Config with Array attributes

Currently have the following configuration and the application works as expected:
#CrossOrigin(origins = { "https://localhost:5000","http://localhost:5000"})
would like to change to something that can be configured in a properties file for different environments. I Can get to work with one Value but can't figure out a way for it to work with more than one. When a properties file is application-dev.properites has:
cors.client.urls=http://localhost:5000,https://localhost:5000
The appropriates values are not loaded with the following declaration:
#CrossOrigin(origins = {"${cors.client.urls}"})
When the properties file is just one value this declaration works as expected.
I know that I am missing something extremely basic.. Appreciate any help.
You can use SpringEL here as mentioned in Reading a List from properties file and load with spring annotation #Value
#CrossOrigin(origins = {#{'${cors.client.urls}'.split(',')}})

Janusgraph how to deal with the global_offline misconfiguration

when i tired to remove an index, I typed wrong GLOBAL_OFFLINE setting in userConfig in the ManagementSystem, which I mistake typed the "index.search.backend" with a directory string ......
when i try to open this janusgraph, the print out as below :
WARN org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration
Local setting index.search.backend=lucene (Type: GLOBAL_OFFLINE) is overridden by globally managed value (/data/lucene). Use the ManagementSystem interface instead of the local configuration to control this setting.
INFO org.janusgraph.diskstorage.Backend - Configuring index [search]
Could not find implementation class: /data/lucene
I wonder whether i could not drop this table at the backend and fix this problem !
many thx !
I think i have fix this problem !
I just use the KCVS backend , and find out the source code of GraphDatabaseConfiguration ;
I tried and get the KCVSConfig use the code following :
PropertiesConfiguration configuration = new PropertiesConfiguration(GRAPH_PROPERTIES);
ReadConfiguration localConfig = new CommonsConfiguration(configuration);
BasicConfiguration localBasicConfiguration = new BasicConfiguration(ROOT_NS,localConfig, BasicConfiguration.Restriction.NONE);
KeyColumnValueStoreManager storeManager = Backend.getStorageManager(localBasicConfiguration);
KCVSConfiguration KCVSConfig =Backend.getStandaloneGlobalConfiguration(storeManager,localBasicConfiguration);
Just using the KCVSConfiguration to remove all the index configuration !

How to set a context variable with dot in name?

I am trying to add a context data variable (CDV), which has a dot in its name. According to Adobe site this is correct:
s.contextData['myco.rsid'] = 'value'
Unfortunately, after calling s.t() the variable is split into two or more:
Context Variables
myco.:
rsid: value
.myco:
How can I set the variable and prevent splitting it into pieces?
You are setting it properly already. If you are referring to what you see in the request URL, that's how the Adobe library sends it. In your example, "myco" is a namespace, and "rsid" is a variable in that namespace. And you can have other variables in that namespace. For example if you have
s.contextData['myco.rsid1'] = 'value';
s.contextData['myco.rsid2'] = 'value';
You would see in the AA request URL (just showing the relevant part):
c.&myco.&rsid1=value&rsid2=value&.myco&.c
I assume you are asking because you want to more easily parse/qa AA collection request URLs from the browser network tab, extension, or some unit tester? There is no way to force AA to not behave like this when using dot syntax (namespaces) in your variables.
But, there isn't anything particularly special about using namespaces for your contextData variables; it's just there for your own organization if you choose. So if you want all variables to be "top level" and show full names in the request URL, then do not use dot syntax.
If you want to still have some measure of organization/hierarchy, I suggest you instead use an underscore _ :
s.contextData['myco_rsid1'] = 'value';
s.contextData['myco_rsid2'] = 'value';
Which will give you:
c.&myco_rsid1=value&myco_rsid2=value&.c
Side Note: You cannot do full object/dot notation syntax with s.contextData, e.g.
s.contextData = {
foo:'bar', // <--- this will properly parse
myco:{ // this will not properly parse
rsid:'value' //
} //
};
AA library does not parse this correctly; it just loops through top level properties of contextData when building the request URL. So if you do full object syntax like above, you will end up with:
c.&foo=bar&myco=%5Bobject%20Object%5D&&.c
foo would be okay, but you end up with just myco with "[object Object]" as the recorded value. Why Adobe didn't allow for full object syntax and just JSON.stringify(s.contextData) ? ¯\_(ツ)_/¯

Where to put Symfony2 custom parameters I need?

I need to have some configuration for my bundle in Symfony2
Where is the best place to put them?
and how can I retrieve them from there?
I used my Default DB parameters in PARAMETERS.INI But I need Extra ones that I can retrieve them personally in code.
One should keep his parameters inside the bundles, for instance
src/Company/SomeBundle/Resources/config/parameters.yml
To define any extra parameters you need, define them in your config.yml file. Something like:
# app/config/config.yml
parameters:
my_mailer.class: Acme\HelloBundle\Mailer
my_mailer.transport: sendmail
Then you can retrieve them anywhere that the service container is available, for example inside a controller, just like you retrieve any other service like doctrine or swiftmailer. For example, in a controller, do
$transport = $this->get('my_mailer.transport');
If you want, you can define these parameters in paramters.ini, you will get the same result.
See the How to expose a Semantic Configuration for a Bundle cookbook entry. One of the advantages of this approach is that you can validate the configuration.
use different parts in parameters.ini file. You could have a prod1 environment using parameters prefixed with prod1 and a prod2 with the same:
parameters.ini:
[parameters]
prod1_database_driver = pdo_mysql
prod1_database_host = 127.0.0.1
# ...
prod2_database_driver = pdo_mysql
prod2_database_host = localhost
They both use the prod.yml configuration but overwrite the stuff you want to read from the parameters.ini:
config_prod1.yml:
imports:
- { resource: config_prod.yml }
// .. overwrite stuff here

the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session?

I'm researching hours and hours, but I could not find any clear, efficient way to make it :/
I have a codeigniter base website in English and I have to add a Polish language now. What is the best way to make my site in 2 language depending visitor selection?
is there any way to create array files for each language and call them in view files depends on Session from lang selection? I don't wanna use database.
Appreciate helps! I'm running out of deadline :/ thanks!!
Have you seen CodeIgniter's Language library?
The Language Class provides functions
to retrieve language files and lines
of text for purposes of internationalization.
In your CodeIgniter system folder you'll
find one called language containing sets
of language files. You can create your
own language files as needed in order
to display error and other messages in
other languages.
Language files are typically stored in
your system/language directory. Alternately
you can create a folder called language
inside your application folder and store
them there. CodeIgniter will look first
in your application/language directory.
If the directory does not exist or the
specified language is not located there
CI will instead look in your global
system/language folder.
In your case...
you need to create a polish_lang.php and english_lang.php inside application/language/polish
then create your keys inside that file (e.g. $lang['hello'] = "Witaj";
then load it in your controller like $this->lang->load('polish_lang', 'polish');
then fetch the line like $this->lang->line('hello'); Just store the return value of this function in a variable so you can use it in your view.
Repeat the steps for the english language and all other languages you need.
Also to add the language to the session, I would define some constants for each language, then make sure you have the session library autoloaded in config/autoload.php, or you load it whenever you need it. Add the users desired language to the session:
$this->session->set_userdata('language', ENGLISH);
Then you can grab it anytime like this:
$language = $this->session->userdata('language');
In the controller add following lines when you make the cunstructor
i.e, after
parent::Controller();
add below lines
$this->load->helper('lang_translate');
$this->lang->load('nl_site', 'nl'); // ('filename', 'directory')
create helper file lang_translate_helper.php with following function and put it in directory system\application\helpers
function label($label, $obj)
{
$return = $obj->lang->line($label);
if($return)
echo $return;
else
echo $label;
}
for each of the language, create a directory with language abbrevation like en, nl, fr, etc., under
system\application\languages
create language file in above (respective) directory which will contain $lang array holding pairs label=>language_value as given below
nl_site_lang.php
$lang['welcome'] = 'Welkom';
$lang['hello word'] = 'worde Witaj';
en_site_lang.php
$lang['welcome'] = 'Welcome';
$lang['hello word'] = 'Hello Word';
you can store multiple files for same language with differently as per the requirement
e.g, if you want separate language file for managing backend (administrator section) you can use it in controller as $this->lang->load('nl_admin', 'nl');
nl_admin_lang.php
$lang['welcome'] = 'Welkom';
$lang['hello word'] = 'worde Witaj';
and finally
to print the label in desired language, access labels as below in view
label('welcome', $this);
OR
label('hello word', $this);
note the space in hello & word you can use it like this way as well :)
whene there is no lable defined in the language file, it will simply print it what you passed to the function label.
I second Randell's answer.
However, one could always integrate a GeoIP such as http://www.maxmind.com/app/php
or http://www.ipinfodb.com/. Then you can save the results with the codeigniter session class.
If you want to use the ipinfodb.com api You can add the ip2locationlite.class.php file to your codeigniter application library folder and then create a model function to do whatever geoip logic you need for your application, such as:
function geolocate()
{
$ipinfodb = new ipinfodb;
$ipinfodb->setKey('API KEY');
//Get errors and locations
$locations = $ipinfodb->getGeoLocation($this->input->ip_address());
$errors = $ipinfodb->getError();
//Set geolocation cookie
if(empty($errors))
{
foreach ($locations as $field => $val):
if($field === 'CountryCode')
{
$place = $val;
}
endforeach;
}
return $place;
}
For easier use CI have updated this so you can just use
$this->load->helper('language');
and to translate text
lang('language line');
and if you want to warp it inside label then use optional parameter
lang('language line', 'element id');
This will output
// becomes <label for="form_item_id">language_key</label>
For good reading
http://ellislab.com/codeigniter/user-guide/helpers/language_helper.html
I've used Wiredesignz's MY_Language class with great success.
I've just published it on github, as I can't seem to find a trace of it anywhere.
https://github.com/meigwilym/CI_Language
My only changes are to rename the class to CI_Lang, in accordance with the new v2 changes.
When managing the actual files, things can get out of sync pretty easily unless you're really vigilant. So we've launched a (beta) free service called String which allows you to keep track of your language files easily, and collaborate with translators.
You can either import existing language files (in PHP array, PHP Define, ini, po or .strings formats) or create your own sections from scratch and add content directly through the system.
String is totally free so please check it out and tell us what you think.
It's actually built on Codeigniter too! Check out the beta at http://mygengo.com/string
Follow this https://github.com/EllisLab/CodeIgniter/wiki/CodeIgniter-2.1-internationalization-i18n
its simple and clear, also check out the document # http://ellislab.com/codeigniter/user-guide/libraries/language.html
its way simpler than
I am using such code in config.php:
$lang = 'ru'; // this language will be used if there is no any lang information from useragent (for example, from command line, wget, etc...
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
$tmp_value = $_COOKIE['language'];
if (!empty($tmp_value)) $lang = $tmp_value;
switch ($lang)
{
case 'ru':
$config['language'] = 'russian';
setlocale(LC_ALL,'ru_RU.UTF-8');
break;
case 'uk':
$config['language'] = 'ukrainian';
setlocale(LC_ALL,'uk_UA.UTF-8');
break;
case 'foo':
$config['language'] = 'foo';
setlocale(LC_ALL,'foo_FOO.UTF-8');
break;
default:
$config['language'] = 'english';
setlocale(LC_ALL,'en_US.UTF-8');
break;
}
.... and then i'm using usualy internal mechanizm of CI
o, almost forget! in views i using buttons, which seting cookie 'language' with language, prefered by user.
So, first this code try to detect "preffered language" setted in user`s useragent (browser). Then code try to read cookie 'language'. And finaly - switch sets language for CI-application
you can make a function like this
function translateTo($language, $word) {
define('defaultLang','english');
if (isset($lang[$language][$word]) == FALSE)
return $lang[$language][$word];
else
return $lang[defaultLang][$word];
}
Friend, don't worry, if you have any application installed built in codeigniter and you wanna add some language pack just follow these steps:
1. Add language files in folder application/language/arabic (i add arabic lang in sma2 built in ci)
2. Go to the file named setting.php in application/modules/settings/views/setting.php. Here you find the array
<?php /*
$lang = array (
'english' => 'English',
'arabic' => 'Arabic', // i add this here
'spanish' => 'Español'
Now save and run the application. It's worked fine.

Resources