Exemplo n.º 1
0
function format_language($language_iso, $culture = null)
{
    $c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
    $languages = $c->getLanguages();
    if (!isset($languages[$language_iso])) {
        $c = new sfCultureInfo(sfConfig::get('sf_default_culture'));
        $languages = $c->getLanguages();
    }
    return isset($languages[$language_iso]) ? $languages[$language_iso] : $language_iso;
}
 /**
  * Set the country list via the sfCultureInfo system.
  * @return void
  */
 protected function setCountriesFromCultureInfo()
 {
     $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
     $countries = $c->getCountries();
     foreach ($countries as $key => $value) {
         if (is_int($key)) {
             unset($countries[$key]);
         }
     }
     unset($countries['ZZ']);
     $countries = array('' => '--') + $countries;
     $this->setCountries($countries);
 }
 public function setup()
 {
     parent::setup();
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(sfConfig::get('app_a_i18n_languages'));
     $this->setWidget('culture', new sfWidgetFormChoice(array('choices' => $languages)));
 }
 public function setup()
 {
     parent::setup();
     unset($this['created_at'], $this['updated_at']);
     // checking that some polls are available
     if (false === aPollToolkit::getAvailablePolls(false)) {
         throw new sfException('Cannot find any poll item in apoll_settings_available_polls. Please, define some in app.yml');
     }
     $available_polls = aPollToolkit::getAvailablePolls();
     $choices = array();
     $choices_keys = array();
     foreach ($available_polls as $key => $poll) {
         $choices[$key] = isset($poll['name']) ? $poll['name'] : $key;
         $choices_keys[] = $key;
     }
     $this->widgetSchema['type'] = new sfWidgetFormChoice(array('choices' => $choices));
     $this->validatorSchema['type'] = new sfValidatorAnd(array(new sfValidatorChoice(array('choices' => $choices_keys, 'required' => true)), new aPollValidatorPollItem(array('poll_items' => aPollToolkit::getAvailablePolls()))), array('halt_on_error' => true));
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $date_options = array('image' => '/apostrophePlugin/images/a-icon-datepicker.png', 'culture' => $culture, 'config' => '{changeMonth: true,changeYear: true}');
     $time_attributes = array('twenty-four-hour' => true, 'minutes-increment' => 30);
     $this->setWidget('published_from', new aWidgetFormJQueryDateTime(array('date' => $date_options), array('time' => $time_attributes)));
     $this->setWidget('published_to', new aWidgetFormJQueryDateTime(array('date' => $date_options), array('time' => $time_attributes)));
     $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateEndDate'))));
     $this->setWidget('submissions_allow_multiple', new aWidgetFormChoice(array('choices' => array(true => 'Yes', false => 'No'))));
     $this->setWidget('submissions_delay', new sfWidgetFormTime(array('hours' => self::generateTwoCharsRange(0, 120)), $time_attributes));
     // setting translation catalogue
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
     // embedding i18n fields
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(sfConfig::get('app_a_i18n_languages'));
     $this->embedI18n(array_keys($languages));
     foreach ($languages as $key => $value) {
         $this->widgetSchema->setLabel($key, ucfirst($value));
     }
 }
/**
 * Returns a <selectize> tag populated with all the languages in the world (or almost).
 *
 * The select_language_tag builds off the traditional select_tag function, and is conveniently populated with
 * all the languages in the world (sorted alphabetically). Each option in the list has a two or three character
 * language/culture code for its value and the language's name as its display title.  The country data is
 * retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various
 * countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_country_tag:
 *
 * <samp>
 *  <option value="en">English</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_language_tag('language', 'de');
 * </code>
 *
 * @param  string $name     field name
 * @param  string $selected selected field values (two or three-character language/culture code)
 * @param  array  $options  additional HTML compliant <select> tag parameters
 *
 * @return string <selectize> tag populated with all the languages in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function object_multiselect_language_tag($name, $selected = null, $options = array())
{
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $languages = $c->getLanguages();
    if ($language_option = _get_option($options, 'languages')) {
        foreach ($languages as $key => $value) {
            if (!in_array($key, $language_option)) {
                unset($languages[$key]);
            }
        }
    }
    asort($languages);
    $option_tags = options_for_select($languages, $selected, $options);
    unset($options['include_blank'], $options['include_custom']);
    return select_tag($name, $option_tags, $options);
}
Exemplo n.º 6
0
function render_field($field, $resource, array $options = array())
{
    $options += array('name' => $field->getName());
    $div = null;
    $culture = sfContext::getInstance()->user->getCulture();
    if (isset($resource) && $culture != $resource->sourceCulture && 0 < strlen($source = $resource->__get($options['name'], array('sourceCulture' => true)))) {
        // TODO Are there cases where the direction of this <div/>'s containing
        // block isn't the direction of the current culture?
        $dir = null;
        $sourceCultureInfo = sfCultureInfo::getInstance($resource->sourceCulture);
        if (sfCultureInfo::getInstance($culture)->direction != $sourceCultureInfo->direction) {
            $dir = " dir=\"{$sourceCultureInfo->direction}\"";
        }
        $div = <<<div
<div class="default-translation"{$dir}>
  {$source}
</div>

div;
    }
    unset($options['name']);
    return <<<return
<div class="form-item">
  {$field->renderLabel()}
  {$field->renderError()}
  {$div}
  {$field->render($options)}
  {$field->renderHelp()}
</div>

return;
}
 protected function addField($name)
 {
     switch ($name) {
         case 'username':
             $this->form->setDefault('username', $this->resource->username);
             $this->form->setValidator('username', new sfValidatorString(array('required' => true)));
             $this->form->setWidget('username', new sfWidgetFormInput());
             break;
         case 'email':
             $this->form->setDefault('email', $this->resource->email);
             $this->form->setValidator('email', new sfValidatorEmail(array('required' => true)));
             $this->form->setWidget('email', new sfWidgetFormInput());
             break;
         case 'password':
         case 'confirmPassword':
             $this->form->setDefault($name, null);
             // Required field only if a new user is being created
             $this->form->setValidator($name, new sfValidatorString(array('required' => !isset($this->getRoute()->resource))));
             $this->form->setWidget($name, new sfWidgetFormInputPassword());
             break;
         case 'groups':
             $values = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclUserGroup::USER_ID, $this->resource->id);
             foreach (QubitAclUserGroup::get($criteria) as $item) {
                 $values[] = $item->groupId;
             }
             $choices = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclGroup::ID, 99, Criteria::GREATER_THAN);
             foreach (QubitAclGroup::get($criteria) as $item) {
                 $choices[$item->id] = $item->getName(array('cultureFallback' => true));
             }
             $this->form->setDefault('groups', $values);
             $this->form->setValidator('groups', new sfValidatorPass());
             $this->form->setWidget('groups', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'translate':
             $c = sfCultureInfo::getInstance($this->context->user->getCulture());
             $languages = $c->getLanguages();
             $choices = array();
             if (0 < count($langSettings = QubitSetting::getByScope('i18n_languages'))) {
                 foreach ($langSettings as $item) {
                     $choices[$item->name] = $languages[$item->name];
                 }
             }
             // Find existing translate permissions
             $criteria = new Criteria();
             $criteria->add(QubitAclPermission::USER_ID, $this->resource->id);
             $criteria->add(QubitAclPermission::ACTION, 'translate');
             $defaults = null;
             if (null !== ($permission = QubitAclPermission::getOne($criteria))) {
                 $defaults = $permission->getConstants(array('name' => 'languages'));
             }
             $this->form->setDefault('translate', $defaults);
             $this->form->setValidator('translate', new sfValidatorPass());
             $this->form->setWidget('translate', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
     }
 }
 public function getComputedAddress($culture = 'en')
 {
     $address = $this->getField(Petition::FIELD_ADDRESS);
     $postcode = $this->getField(Petition::FIELD_POSTCODE);
     $city = $this->getField(Petition::FIELD_CITY);
     try {
         $country = sfCultureInfo::getInstance($culture)->getCountry($this->getField(Petition::FIELD_COUNTRY));
     } catch (Exception $e) {
         $country = $this->getField(Petition::FIELD_COUNTRY);
     }
     $ret = $this->getComputedName();
     if ($address) {
         $ret .= "\n" . $address;
     }
     if ($city) {
         if ($postcode) {
             $ret .= "\n" . $postcode . ' ' . $city;
         } else {
             $ret .= "\n" . $city;
         }
     } else {
         if ($postcode) {
             $ret .= "\n" . $postcode;
         }
     }
     if ($country) {
         $ret .= "\n" . $country;
     }
     return $ret;
 }
Exemplo n.º 9
0
 public function configure()
 {
     unset($this['status'], $this['campaign_id'], $this['first_widget_id'], $this['email']);
     $this->widgetSchema->setFormFormatterName('policat');
     $countries_false = array_keys(sfCultureInfo::getInstance()->getCountries());
     $countries = array();
     foreach ($countries_false as $country) {
         if (!is_numeric($country)) {
             $countries[] = $country;
         }
     }
     $countries = array_diff($countries, array('QU', 'ZZ', 'MF'));
     $this->setWidget('country', new sfWidgetFormI18nChoiceCountry(array('countries' => $countries, 'add_empty' => 'Country')));
     $this->setValidator('country', new sfValidatorI18nChoiceCountry(array('countries' => $countries, 'required' => true)));
     //$this->setValidator('email', new ValidatorEmail());
     $this->setWidget('password', new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off')));
     $this->setValidator('password', new sfValidatorString(array('min_length' => 20, 'max_length' => 100, 'required' => true)));
     $this->setWidget('password_again', new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off')));
     $this->setValidator('password_again', new sfValidatorString());
     $this->getWidgetSchema()->moveField('password_again', sfWidgetFormSchema::AFTER, 'password');
     $this->getValidatorSchema()->setPostValidator(new sfValidatorSchemaCompare('password', '===', 'password_again', array(), array('invalid' => 'passwords do not match')));
     $this->getWidgetSchema()->setHelp('password', 'at least 20 characters');
     foreach (array('firstname', 'lastname', 'function', 'organisation', 'phone', 'address') as $field) {
         $this->getValidator($field)->setOption('required', true);
     }
 }
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $this->addOption('culture', $culture);
     $this->addOption('languages');
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($options['languages']) ? $options['languages'] : null);
     $cultures = sfCultureInfo::getInstance($culture)->getCultures();
     $countries = sfCultureInfo::getInstance($culture)->getCountries();
     $values = array();
     foreach ($cultures as $key => $culture_info) {
         if (strlen($culture_info) == 5) {
             $culture_small = substr($culture_info, 0, 2);
             $countrie_small = substr($culture_info, 3, 2);
             if (array_key_exists($culture_small, $languages) && array_key_exists($countrie_small, $countries)) {
                 $select_language = preg_replace('/^[' . $culture_small . ']{2}/i', $languages[$culture_small], $culture_info);
                 $select = preg_replace('/[' . $countrie_small . ']{2}$/i', '(' . $countries[$countrie_small] . ')', $select_language);
                 $values[$culture_info] = ucfirst(str_replace('_', ' ', $select));
             }
         }
     }
     if (count($values) == 0) {
         $values[''] = 'No languages found';
     }
     asort($values);
     $this->setOption('choices', $values);
 }
 function _current_language()
 {
     try {
         return sfContext::getInstance()->getUser()->getCulture();
     } catch (Exception $e) {
         return sfCultureInfo::getInstance()->getName();
     }
 }
 /**
  * Configures the current validator.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * countries: An array of country codes to use (ISO 3166)
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->addRequiredOption('culture');
     $this->addOption('countries');
     // populate choices with all countries
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $cultureInfo = new sfCultureInfo($culture);
     $countries = array_keys($cultureInfo->getCountries());
     // restrict countries to a sub-set
     if (isset($options['countries'])) {
         if ($problems = array_diff($options['countries'], $countries)) {
             throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
         }
         $countries = $options['countries'];
     }
     sort($countries);
     $this->setOption('choices', $countries);
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * languages: An array of language codes to use (ISO 639-1)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $this->addOption('languages');
     // populate choices with all languages
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $cultureInfo = new sfCultureInfo($culture);
     $languages = $cultureInfo->getLanguages();
     // restrict languages to a sub-set
     if (isset($options['languages'])) {
         if ($problems = array_diff($options['languages'], array_keys($languages))) {
             throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
         }
         $languages = array_intersect_key($languages, array_flip($options['languages']));
     }
     asort($languages);
     $this->setOption('choices', $languages);
 }
Exemplo n.º 14
0
 protected function getCultureSelect()
 {
     if ($this->i18n->hasManyCultures()) {
         $cultures = array();
         foreach ($this->i18n->getCultures() as $key) {
             $cultures[$key] = sfCultureInfo::getInstance($key)->getLanguage($key);
         }
         return new sfWidgetFormSelect(array('choices' => $cultures));
     }
 }
 /**
  * Embed i18n to the given form if it is enabled
  *
  * @param string $name 
  * @param sfForm $form 
  * @return void
  */
 public static function embedI18n($name, sfForm $form)
 {
     if (sfSympalConfig::isI18nEnabled($name)) {
         $context = sfContext::getInstance();
         $culture = $context->getUser()->getEditCulture();
         $form->embedI18n(array(strtolower($culture)));
         $widgetSchema = $form->getWidgetSchema();
         $context->getConfiguration()->loadHelpers(array('Helper'));
         $c = sfCultureInfo::getInstance($culture);
         $languages = $c->getLanguages();
         $language = isset($languages[$culture]) ? $languages[$culture] : '';
         $widgetSchema[$culture]->setLabel($language);
     }
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings
  *  * add_empty: Whether to add a first empty value or not (false by default)
  *               If the option is not a Boolean, the value will be used as the text value
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormChoice
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addOption('culture');
     $this->addOption('add_empty', false);
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $timezones = array_keys(sfCultureInfo::getInstance($culture)->getTimeZones());
     $timezones = array_combine($timezones, $timezones);
     $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
     if (false !== $addEmpty) {
         $timezones = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $timezones);
     }
     $this->setOption('choices', $timezones);
 }
 /**
  * Configures the current validator.
  *
  * Available options:
  *
  *  * languages: An array of language codes to use
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->addOption('languages');
     // populate choices with all languages
     $languages = array_keys(sfCultureInfo::getInstance()->getLanguages());
     // restrict languages to a sub-set
     if (isset($options['languages'])) {
         if ($problems = array_diff($options['languages'], $languages)) {
             throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
         }
         $languages = $options['languages'];
     }
     $this->setOption('choices', $languages);
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings
  *  * countries: An array of country codes to use (ISO 3166)
  *  * add_empty: Whether to add a first empty value or not (false by default)
  *               If the option is not a Boolean, the value will be used as the text value
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormChoice
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addOption('culture');
     $this->addOption('countries');
     $this->addOption('add_empty', false);
     // populate choices with all countries
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $countries = sfCultureInfo::getInstance($culture)->getCountries(isset($options['countries']) ? $options['countries'] : null);
     $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
     if (false !== $addEmpty) {
         $countries = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $countries);
     }
     $this->setOption('choices', $countries);
 }
 public function getChoices()
 {
     // populate choices with all languages
     $culture = isset($this->options['culture']) ? $this->options['culture'] : 'en';
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($this->options['languages']) ? $this->options['languages'] : null);
     foreach ($languages as $iso => $language) {
         if (!sfCultureInfo::validCulture($iso)) {
             unset($languages[$iso]);
         }
     }
     $addEmpty = isset($this->options['add_empty']) ? $this->options['add_empty'] : false;
     if (false !== $addEmpty) {
         $languages = array('' => true === $addEmpty ? '' : $addEmpty) + $languages;
     }
     return $languages;
 }
 public function configure()
 {
     $this->widgetSchema->setFormFormatterName('bootstrap');
     $this->widgetSchema->setNameFormat('country[%s]');
     $culture_info = sfCultureInfo::getInstance('en');
     $countries_false = array_keys($culture_info->getCountries());
     $countries_all = array();
     foreach ($countries_false as $country) {
         if (!is_numeric($country)) {
             $countries_all[] = $country;
         }
     }
     $countries = array_diff($countries_all, array('QU', 'ZZ'));
     unset($this['countries']);
     $this->setWidget('countries_list', new sfWidgetFormI18nChoiceCountry(array('multiple' => true, 'countries' => $countries, 'culture' => $culture_info->getName(), 'label' => 'Countries', 'default' => $this->getObject()->getCountriesList())));
     $this->setValidator('countries_list', new sfValidatorI18nChoiceCountry(array('multiple' => true, 'min' => 1, 'required' => true, 'countries' => $countries)));
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings
  *  * languages: An array of language codes to use
  *  * add_empty: Whether to add a first empty value or not (false by default)
  *               If the option is not a Boolean, the value will be used as the text value
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormChoice
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addOption('culture');
     $this->addOption('languages');
     $this->addOption('add_empty', false);
     // populate choices with all languages
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $kk_lang = isset($options['languages']) == true ? $options['languages'] : null;
     //var_dump(sfCultureInfo::getInstance($culture)->getLanguages());
     //exit;
     $languages = sfCultureInfo::getInstance($culture)->getLanguages();
     $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
     if (false !== $addEmpty) {
         $languages = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $languages);
     }
     $this->setOption('choices', $languages);
 }
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addOption('currencies');
     $this->addOption('culture', sfContext::getInstance()->getUser()->getCulture());
     $this->addOption('add_empty', false);
     $culture = $this->getOption('culture');
     $currencies = sfCultureInfo::getInstance($culture)->getCurrencies(isset($options['currencies']) ? $options['currencies'] : null);
     $a_currencies = array();
     foreach ($currencies as $code => $name) {
         $a_currencies[$code] = strtoupper($code) . ' - ' . ucfirst($name);
     }
     asort($a_currencies);
     $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
     if (false !== $addEmpty) {
         $a_currencies = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $a_currencies);
     }
     $this->setOption('choices', $a_currencies);
 }
 /**
  * Configures the current validator.
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     // populate choices with all cultures
     $choices = array();
     $cultures = sfCultureInfo::getCultures(sfCultureInfo::SPECIFIC);
     foreach ($cultures as $culture) {
         // skip en_US_POSIX
         if ($culture == "en_US_POSIX") {
             continue;
         }
         try {
             $choices[] = sfCultureInfo::getInstance($culture)->getName();
         } catch (sfException $e) {
         }
     }
     sort($choices);
     $this->setOption('choices', $choices);
 }
Exemplo n.º 24
0
 /**
  * Returns the sfDateTimeFormatInfo associated with the specified culture.
  *
  * @param sfCultureInfo   $culture  the culture that gets the sfDateTimeFormat property.
  * @return sfDateTimeFormatInfo sfDateTimeFormatInfo for the specified
  * culture.
  */
 static function getInstance($culture = null)
 {
     if ($culture instanceof sfCultureInfo) {
         return $culture->DateTimeFormat;
     } else {
         if (is_string($culture)) {
             return sfCultureInfo::getInstance($culture)->DateTimeFormat;
         } else {
             return sfCultureInfo::getInvariantCulture()->DateTimeFormat;
         }
     }
 }
Exemplo n.º 25
0
 public function printLang()
 {
     return sprintf('%s', sfCultureInfo::getInstance()->getLanguage($this->getLang()));
 }
 /**
  * Gets the list of supported cultures filtered by the specified 
  * culture type. This is an EXPENSIVE function, it needs to traverse
  * a list of ICU files in the data directory.
  * This function can be called statically.
  *
  * @param int $type culture type, sfCultureInfo::ALL, sfCultureInfo::NEUTRAL
  * or sfCultureInfo::SPECIFIC.
  * @return array list of culture information available. 
  */
 static function getCultures($type = sfCultureInfo::ALL)
 {
     $dataDir = sfCultureInfo::dataDir();
     $dataExt = sfCultureInfo::fileExt();
     $dir = dir($dataDir);
     $neutral = array();
     $specific = array();
     while (false !== ($entry = $dir->read())) {
         if (is_file($dataDir . $entry) && substr($entry, -4) == $dataExt && $entry != 'root' . $dataExt) {
             $culture = substr($entry, 0, -4);
             if (strlen($culture) == 2) {
                 $neutral[] = $culture;
             } else {
                 $specific[] = $culture;
             }
         }
     }
     $dir->close();
     switch ($type) {
         case sfCultureInfo::ALL:
             $all = array_merge($neutral, $specific);
             sort($all);
             return $all;
             break;
         case sfCultureInfo::NEUTRAL:
             return $neutral;
             break;
         case sfCultureInfo::SPECIFIC:
             return $specific;
             break;
     }
 }
Exemplo n.º 27
0
/**
 * Returns a <select> tag populated with all the timezones in the world.
 *
 * The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with 
 * all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier 
 * for its value and the timezone's locale as its display title.  The timezone data is retrieved via the sfCultureInfo
 * class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
 * Here's an example of an <option> tag generated by the select_timezone_tag:
 *
 * <b>Options:</b>
 * - display - 
 *     identifer         - Display the PHP timezone identifier (e.g. America/Denver)
 *     timezone          - Display the full timezone name (e.g. Mountain Standard Time)
 *     timezone_abbr     - Display the timezone abbreviation (e.g. MST)
 *     timzone_dst       - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
 *     timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
 *     city              - Display the city/region that relates to the timezone (e.g. Denver)
 * 
 * <samp>
 *  <option value="America/Denver">America/Denver</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_timezone_tag('timezone', 'America/Denver');
 * </code>
 *
 * @param  string field name 
 * @param  string selected field value (timezone identifier)
 * @param  array  additional HTML compliant <select> tag parameters
 * @return string <select> tag populated with all the timezones in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function select_timezone_tag($name, $selected = null, $options = array())
{
    if (!isset($options['display'])) {
        $options['display'] = 'identifier';
    }
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $timezone_groups = $c->getTimeZones();
    $display_key = 0;
    switch ($options['display']) {
        case "identifier":
            $display_key = 0;
            break;
        case "timezone":
            $display_key = 1;
            break;
        case "timezone_abbr":
            $display_key = 2;
            break;
        case "timezone_dst":
            $display_key = 3;
            break;
        case "timezone_dst_abbr":
            $display_key = 4;
            break;
        case "city":
            $display_key = 5;
            break;
        default:
            $display_key = 0;
            break;
    }
    unset($options['display']);
    $timezones = array();
    foreach ($timezone_groups as $tz_group_key => $tz_group) {
        $array_key = null;
        foreach ($tz_group as $tz_key => $tz) {
            if ($tz_key == 0) {
                $array_key = $tz;
            }
            if ($tz_key == $display_key and !empty($tz)) {
                $timezones[$array_key] = $tz;
            }
        }
    }
    if ($timezone_option = _get_option($options, 'timezones')) {
        $diff = array_diff_key($timezones, array_flip((array) $timezone_option));
        foreach ($diff as $key => $v) {
            unset($timezones[$key]);
        }
    }
    // Remove duplicate values
    $timezones = array_unique($timezones);
    asort($timezones);
    $option_tags = options_for_select($timezones, $selected);
    return select_tag($name, $option_tags, $options);
}
Exemplo n.º 28
0
/**
 * Returns a <select> tag populated with all the timezones in the world.
 *
 * The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with 
 * all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier 
 * for its value and the timezone's locale as its display title.  The timezone data is retrieved via the sfCultureInfo
 * class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
 * Here's an example of an <option> tag generated by the select_timezone_tag:
 *
 * <b>Options:</b>
 * - display - 
 *     identifer         - Display the PHP timezone identifier (e.g. America/Denver)
 *     timezone          - Display the full timezone name (e.g. Mountain Standard Time)
 *     timezone_abbr     - Display the timezone abbreviation (e.g. MST)
 *     timzone_dst       - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
 *     timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
 *     city              - Display the city/region that relates to the timezone (e.g. Denver)
 * 
 * <samp>
 *  <option value="America/Denver">America/Denver</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_timezone_tag('timezone', 'America/Denver');
 * </code>
 *
 * @param  string $name      field name 
 * @param  string $selected  selected field value (timezone identifier)
 * @param  array  $options   additional HTML compliant <select> tag parameters
 *
 * @return string <select> tag populated with all the timezones in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function select_timezone_tag($name, $selected = null, $options = array())
{
    static $display_keys = array('identifier' => 0, 'timezone' => 1, 'timezone_abbr' => 2, 'timezone_dst' => 3, 'timezone_dst_abbr' => 4, 'city' => 5);
    $display = _get_option($options, 'display', 'identifier');
    $display_key = isset($display_keys[$display]) ? $display_keys[$display] : 0;
    $c = sfCultureInfo::getInstance(sfContext::getInstance()->getUser()->getCulture());
    $timezone_groups = $c->getTimeZones();
    $timezones = array();
    foreach ($timezone_groups as $tz_group) {
        $array_key = isset($tz_group[0]) ? $tz_group[0] : null;
        if (isset($tz_group[$display_key]) and !empty($tz_group[$display_key])) {
            $timezones[$array_key] = $tz_group[$display_key];
        }
    }
    if ($timezone_option = _get_option($options, 'timezones')) {
        $timezones = array_intersect_key($timezones, array_flip((array) $timezone_option));
    }
    // Remove duplicate values
    $timezones = array_unique($timezones);
    asort($timezones);
    $option_tags = options_for_select($timezones, $selected);
    return select_tag($name, $option_tags, $options);
}
Exemplo n.º 29
0
function format_language($language_iso, $culture = null)
{
    $c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
    $languages = $c->getLanguages();
    return isset($languages[$language_iso]) ? $languages[$language_iso] : '';
}
Exemplo n.º 30
0
<?php

op_mobile_page_title($member->getName());
$culture = sfCultureInfo::getInstance($sf_user->getCulture());
?>

<?php 
if ($member == $sf_user->getMember()) {
    ?>
<font color="<?php 
    echo $op_color["core_color_22"];
    ?>
">
<?php 
    echo __('This is your page other member see.');
    ?>
<br>
<?php 
    echo __('If you edit profile, access %1%.', array('%1%' => link_to('「' . __('Edit profile') . '」', 'member/editProfile')));
    ?>
</font>
<?php 
} else {
    include_partial('member/birthdayBox', array('targetDay' => $targetDay));
}
?>

<?php 
if ($mobileTopGadgets) {
    foreach ($mobileTopGadgets as $gadget) {
        if ($gadget->isEnabled()) {