Exemplo n.º 1
0
 function testCreate()
 {
     // attempt to create non-existing locale
     $locale = Locale::getInstance('enz');
     //$this->assertFalse($locale);
     // create existing locale
     $locale = Locale::getInstance('en');
     $this->assertTrue($locale instanceof Locale);
     // set as current locale
     Locale::setCurrentLocale('en');
     $current = Locale::getCurrentLocale();
     $this->assertSame($current, $locale);
 }
Exemplo n.º 2
0
 private function getUserAddress($data, $prefix)
 {
     $address = UserAddress::getNewInstance();
     $map = array('company' => 'companyName', 'street_address' => 'address1', 'city' => 'city', 'postcode' => 'postalCode', 'state' => 'stateName', 'firstname' => 'firstName', 'lastname' => 'lastName');
     foreach ($map as $osc => $lc) {
         if (isset($data[$prefix . $osc])) {
             $address->{$lc}->set($data[$prefix . $osc]);
         }
     }
     if (!empty($data[$prefix . 'name'])) {
         $names = explode(' ', $data[$prefix . 'name'], 2);
         $address->firstName->set(array_shift($names));
         $address->lastName->set(array_shift($names));
     }
     if (isset($data['customers_telephone'])) {
         $address->phone->set($data['customers_telephone']);
     }
     if (isset($data[$prefix . 'country'])) {
         $country = array_search($data[$prefix . 'country'], Locale::getInstance('en')->info()->getAllCountries());
         if (!$country) {
             $country = 'US';
         }
         $address->countryID->set($country);
     }
     return $address;
 }
Exemplo n.º 3
0
 private function loadLocale()
 {
     if (empty($this->locale)) {
         ClassLoader::import('library.locale.Locale');
         $this->locale = Locale::getInstance($this->localeName);
         $this->locale->translationManager()->setCacheFileDir(ClassLoader::getRealPath('storage.language'));
         foreach ($this->getConfigContainer()->getLanguageDirectories() as $dir) {
             $this->locale->translationManager()->setDefinitionFileDir($dir);
         }
         $this->locale->translationManager()->setDefinitionFileDir(ClassLoader::getRealPath('storage.language'));
         Locale::setCurrentLocale($this->localeName);
         $this->loadLanguageFiles();
     }
     return $this->locale;
 }
 private function initLocales()
 {
     ClassLoader::import('library.locale.Locale');
     $filter = new ARSelectFilter();
     $filter->setOrder(new ARFieldHandle("Language", "position"), ARSelectFilter::ORDER_ASC);
     $filter->setCondition(new EqualsCond(new ARFieldHandle("Language", "isEnabled"), 1));
     if (count($this->limitToLocales) > 0) {
         $z = array();
         foreach ($this->limitToLocales as $localeCode) {
             $z[] = new EqualsCond(new ARFieldHandle("Language", "ID"), $localeCode);
         }
         $filter->mergeCondition(new OrChainCondition($z));
         // new INCond()
     }
     $languages = ActiveRecord::getRecordSetArray("Language", $filter);
     foreach ($languages as $language) {
         $locale = Locale::getInstance($language['ID']);
         $locale->translationManager()->setCacheFileDir(ClassLoader::getRealPath('storage.language'));
         foreach ($this->application->getConfigContainer()->getLanguageDirectories() as $dir) {
             $locale->translationManager()->setDefinitionFileDir($dir);
         }
         $locale->translationManager()->setDefinitionFileDir(ClassLoader::getRealPath('storage.language'));
         $locale->translationManager()->loadFile('backend/Settings');
         $this->locales[$language['ID']] = $locale;
     }
     $this->localeCodes = array_keys($this->locales);
 }
Exemplo n.º 5
0
Arquivo: Email.php Projeto: saiber/www
 public function send()
 {
     ClassLoader::ignoreMissingClasses();
     $this->application->processInstancePlugins('email-prepare-send', $this);
     $this->application->processInstancePlugins('email-prepare-send/' . $this->relativeTemplatePath, $this);
     if ($this->template) {
         $originalLocale = $this->application->getLocale();
         $emailLocale = Locale::getInstance($this->getLocale());
         $this->application->setLocale($emailLocale);
         $this->application->getLocale()->translationManager()->loadFile('User');
         $this->application->loadLanguageFiles();
         $smarty = $this->application->getRenderer()->getSmartyInstance();
         foreach ($this->values as $key => $value) {
             $smarty->assign($key, $value);
         }
         $router = $this->application->getRouter();
         $smarty->assign('html', false);
         $smarty->disableTemplateLocator();
         $text = $smarty->fetch($this->template);
         $smarty->enableTemplateLocator();
         $parts = explode("\n", $text, 2);
         $this->subject = array_shift($parts);
         $this->setText(array_shift($parts));
         // fix URLs
         $this->text = str_replace('&', '&', $this->text);
         if ($this->application->getConfig()->get('HTML_EMAIL')) {
             $smarty->assign('html', true);
             $html = array_pop(explode("\n", $smarty->fetch($this->template), 2));
             $css = new EditedCssFile('email');
             $smarty->assign('cssStyle', str_replace("\n", ' ', $css->getCode()));
             $smarty->assign('messageHtml', $html);
             $html = $smarty->fetch($this->getTemplatePath('htmlWrapper'));
             $this->setHtml($html);
         }
         $this->application->setLocale($originalLocale);
     }
     $this->application->processInstancePlugins('email-before-send', $this);
     $this->application->processInstancePlugins('email-before-send/' . $this->relativeTemplatePath, $this);
     $this->message->setSubject($this->subject);
     if ($this->html) {
         preg_match_all('/\\#\\#([_\\-\\.a-zA-Z0-9\\/]+)\\#\\#/msU', $this->html, $matches);
         $html = $this->html;
         if (!empty($matches[1])) {
             foreach ($matches[1] as $match) {
                 $html = str_replace('##' . $match . '##', $this->message->embed(Swift_Image::fromPath(ClassLoader::getRealPath('public.') . $match)), $html);
             }
         }
         preg_match_all('/src\\=\\"([\\:_\\-\\.a-zA-Z0-9\\/]+)\\"/msU', $this->html, $matches);
         if (!empty($matches[1])) {
             foreach ($matches[1] as $match) {
                 if (substr($match, 0, 4) == 'http') {
                     if (substr($match, 0, strlen($this->url)) == $this->url) {
                         $match = substr($match, strlen($this->url));
                     }
                 }
                 if (!substr($match, 0, 4) == 'http') {
                     $match = $this->message->embed(Swift_Image::fromPath(ClassLoader::getRealPath('public.') . $match));
                 }
                 $html = str_replace('src="' . $match . '"', 'src="' . $match . '"', $html);
             }
             $html = str_replace('src="upload', 'src="' . $this->url . '/upload', $html);
         }
         $this->message->setBody($html, 'text/html');
     }
     if ($this->text) {
         if (!$this->html) {
             $this->message->setBody($this->text, 'text/plain');
         } else {
             $this->message->addPart($this->text, 'text/plain');
         }
     }
     if (!$this->text && !$this->html) {
         return false;
     }
     try {
         $res = $this->swiftInstance->send($this->message);
         ClassLoader::ignoreMissingClasses(false);
     } catch (Exception $e) {
         $this->application->processInstancePlugins('email-fail-send/' . $this->relativeTemplatePath, $this, array('exception' => $e));
         $this->application->processInstancePlugins('email-fail-send', $this, array('exception' => $e));
         ClassLoader::ignoreMissingClasses(false);
         return false;
     }
     $this->application->processInstancePlugins('email-after-send/' . $this->relativeTemplatePath, $this);
     $this->application->processInstancePlugins('email-after-send', $this);
     return $res;
 }
Exemplo n.º 6
0
 /**
  * Gets locale, which is defined as current {@see Locale::setCurrentLocale}
  * @return Locale
  */
 public static function getCurrentLocale()
 {
     return Locale::getInstance(self::$currentLocale);
 }
Exemplo n.º 7
0
 /**
  * Displays translation dialog menu for Live Translations
  *
  * @return ActionResponse
  */
 public function translationDialog()
 {
     $id = $this->request->get('id');
     $file = base64_decode($this->request->get('file'));
     $translation = $this->locale->translationManager()->get($file, $id);
     $defaultTranslation = Locale::getInstance($this->application->getDefaultLanguageCode())->translationManager()->get($file, $id);
     $response = new ActionResponse();
     $response->set('id', $id);
     $response->set('file', $file);
     $response->set('translation', $translation);
     $response->set('defaultTranslation', $defaultTranslation);
     $response->set('language', Language::getInstanceByID($this->locale->getLocaleCode())->toArray());
     return $response;
 }
Exemplo n.º 8
0
 public function send()
 {
     ClassLoader::ignoreMissingClasses();
     $this->application->processInstancePlugins('email-prepare-send', $this);
     $this->application->processInstancePlugins('email-prepare-send/' . $this->relativeTemplatePath, $this);
     if ($this->template) {
         $originalLocale = $this->application->getLocale();
         $emailLocale = Locale::getInstance($this->getLocale());
         $this->application->setLocale($emailLocale);
         $this->application->getLocale()->translationManager()->loadFile('User');
         $this->application->loadLanguageFiles();
         $smarty = $this->application->getRenderer()->getSmartyInstance();
         foreach ($this->values as $key => $value) {
             $smarty->assign($key, $value);
         }
         $router = $this->application->getRouter();
         $smarty->assign('html', false);
         $smarty->disableTemplateLocator();
         $text = $smarty->fetch($this->template);
         $smarty->enableTemplateLocator();
         $parts = explode("\n", $text, 2);
         $this->subject = array_shift($parts);
         $this->setText(array_shift($parts));
         // fix URLs
         $this->text = str_replace('&', '&', $this->text);
         if ($this->application->getConfig()->get('HTML_EMAIL')) {
             $smarty->assign('html', true);
             $html = array_pop(explode("\n", $smarty->fetch($this->template), 2));
             $css = new EditedCssFile('email');
             $smarty->assign('cssStyle', str_replace("\n", ' ', $css->getCode()));
             $smarty->assign('messageHtml', $html);
             $html = $smarty->fetch($this->getTemplatePath('htmlWrapper'));
             $this->setHtml($html);
         }
         $this->application->setLocale($originalLocale);
     }
     $this->application->processInstancePlugins('email-before-send', $this);
     $this->application->processInstancePlugins('email-before-send/' . $this->relativeTemplatePath, $this);
     $this->message->setSubject($this->subject);
     if ($this->html) {
         $this->message->setBody($this->html, 'text/html');
     }
     if ($this->text) {
         if (!$this->html) {
             $this->message->setBody($this->text, 'text/plain');
         } else {
             $this->message->addPart($this->text, 'text/plain');
         }
     }
     if (!$this->text && !$this->html) {
         return false;
     }
     try {
         $res = $this->swiftInstance->send($this->message);
         ClassLoader::ignoreMissingClasses(false);
     } catch (Exception $e) {
         $this->application->processInstancePlugins('email-fail-send/' . $this->relativeTemplatePath, $this, array('exception' => $e));
         $this->application->processInstancePlugins('email-fail-send', $this, array('exception' => $e));
         ClassLoader::ignoreMissingClasses(false);
         return false;
     }
     $this->application->processInstancePlugins('email-after-send/' . $this->relativeTemplatePath, $this);
     $this->application->processInstancePlugins('email-after-send', $this);
     return $res;
 }