public function executeUpload(sfWebRequest $request) { $language = LanguageTable::getInstance()->find($request->getParameter('id')); /* @var $language Language */ if (!$language) { return $this->notFound(); } if ($request->getPostParameter('csrf_token') == UtilCSRF::gen('language_upload', $language->getId())) { $this->ajax()->setAlertTarget('#upload', 'append'); $file = $request->getFiles('file'); if ($file && $file['tmp_name']) { $parser = new sfMessageSource_XLIFF(); if ($parser->loadData($file['tmp_name'])) { $dir = dirname($language->i18nFileWidget()); if (!file_exists($dir)) { mkdir($dir); } move_uploaded_file($file['tmp_name'], $language->i18nFileWidget()); $language->i18nCacheWidgetClear(); return $this->ajax()->alert('Language file updated.', '', null, null, false, 'success')->render(true); } return $this->ajax()->alert('File invalid.', '', null, null, false, 'error')->render(true); } return $this->ajax()->alert('Upload failed.', '', null, null, false, 'error')->render(true); } return $this->notFound(); }
/** * Returns the string representation of this object. * * @return string */ public function __toString() { $user = sfContext::getInstance()->getUser(); $generalCategoryDescriptions = GeneralCategoryDescriptionTable::getInstance()->findByGeneralCategId($this->getId()); if ($user instanceof sfGuardSecurityUser) { $languageId = $user->getGuardUser()->getLanguage()->getId(); //Check if there is description with the user's language foreach ($generalCategoryDescriptions as $generalCategoryDescription) { if ($generalCategoryDescription->getLanguageId() == $languageId) { //We found it!!! return (string) $generalCategoryDescription->getGeneralCategName(); } } } //Otherwise return with the default language $languageCode = sfConfig::get('app_default_language'); $languageId = LanguageTable::getInstance()->findOneByCode($languageCode)->getId(); foreach ($generalCategoryDescriptions as $generalCategoryDescription) { if ($generalCategoryDescription->getLanguageId() == $languageId) { //We found the default name description!!! return (string) $generalCategoryDescription->getGeneralCategName(); } } //Finally, if nothing was found, return nice error message. return (string) "General category without default language"; }
/** * Retrieve the available language's ids. * * @return array an array with the available languages' ids. */ private function availableLanguages() { //Doctrine_Collection with all our languages $languages = LanguageTable::getInstance()->findAll(); //Using Doctrine_Collection_Iterator $iterator = $languages->getIterator(); //Doctrine_Collection with the current descriptions for our ad //When creating the first time a new ad there is not Doctrine_Row for this ad in the Ad Table. //We check that edge condition. if ($this->getObject()->getAd()->exists()) { $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getObject()->getAdId()); } else { $adDescriptions = array(); } $availableLanguages = array(); while ($language = $iterator->current()) { $match = false; foreach ($adDescriptions as $adDescription) { if ($adDescription->getLanguageId() == $language->getId()) { //There is a match $match = true; break; } } if (!$match) { $availableLanguages[] = $language->getId(); } $iterator->next(); } return $availableLanguages; }
/** * switch the language */ public function switchLanguage($culture) { $supported_cultures = LanguageTable::getAllLanguageCodesAsArray(true); if (in_array($culture, $supported_cultures)) { $this->setCulture($culture); } else { $this->setCulture(LanguageTable::getDefaultLanguage()); } $this->setAttribute('culture_set', true); }
public static function createWildcard($wildcard, $catalogue) { // get all available languages $langs = LanguageTable::getAllLanguages(false); foreach ($langs as $l) { $lQuery = Doctrine_Query::create()->from('Catalogue c')->select('c.cat_id')->where('c.name= ?', $catalogue . '.' . $l->getLang()); $catId = $lQuery->execute(array(), Doctrine_Core::HYDRATE_NONE); $catId = HydrationUtils::flattenArray($catId); if (!$catId) { continue; } $t = new TransUnit(); $t->setCatId($catId[0]); $t->setSource($wildcard); $t->save(); } }
public function executeCreate_wildcard(sfWebRequest $request) { if ($request->getParameter('create') == 1) { $this->lWildcardName = $request->getParameter('wildcard_name'); $this->lCreateAfterEmptySearch = true; } else { $this->lWildcardName = ''; $this->lCreateAfterEmptySearch = false; } if ($request->getMethod() == 'POST') { $lWildcardSource = $request->getParameter('wildcard_name'); $lToTranslateParams = $request->getParameter('to_translate'); if ($lWildcardSource == '') { $this->getUser()->setFlash('error', 'Please insert a wildcard name!'); $this->redirect('trans_unit/create_wildcard'); } // create wildcard TransUnitTable::createWildcard($lWildcardSource, 'messages'); // create translations $lTransUnitData = $request->getParameter('wildcard'); foreach (LanguageTable::getAllLanguages(false) as $lCulture) { $lTransUnit = TransUnitTable::retrieveWildcardObject($lCulture, 'messages', $lWildcardSource); $lTransUnit->setTarget($lTransUnitData["{$lCulture}"]['target']); //$lTransUnit->setComments($lTransUnitData['comment']); $lTransUnit->setAuthor('hugo'); //$this->getUser()->getUser()->getFullname()); if (isset($lToTranslateParams["{$lCulture}"]) && $lToTranslateParams["{$lCulture}"] == 'on' || $lTransUnitData["{$lCulture}"]['target'] == '') { $lTransUnit->setTranslated(false); } else { $lTransUnit->setTranslated(true); } $lTransUnit->save(); } $this->getUser()->setFlash('wildcard_edited', $lTransUnit->getId()); //die(); $this->redirect('trans_unit/new'); } }
/** * Returns the string representation of this object. * * @return string */ public function __toString() { $languageId = sfContext::getInstance()->getUser()->getGuardUser()->getLanguage()->getId(); //Check if there is description with the user's language $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getId()); foreach ($adDescriptions as $adDescription) { if ($adDescription->getLanguageId() == $languageId) { //We found it!!! return (string) $adDescription->getAdName(); } } //Otherwise return with the default language $languageCode = sfConfig::get('app_default_language'); $languageId = LanguageTable::getInstance()->findOneByCode($languageCode)->getId(); foreach ($adDescriptions as $adDescription) { if ($adDescription->getLanguageId() == $languageId) { //We found the default language!!! return (string) $adDescription->getAdName(); } } //Finally, if nothing was found, return nice error message. return (string) "Ad without default language"; }
public function executeEdit(sfWebRequest $request) { $key = $request->getParameter('key'); if (!array_key_exists($key, StoreTable::$meta)) { return $this->notFound(); } $meta = StoreTable::$meta[$key]; $this->title = $meta['name']; $this->key = $key; $route_params = $this->getRoute()->getParameters(); $language_id = null; if (isset($route_params['type']) && $route_params['type'] == 'language') { $language_id = $request->getParameter('language'); $this->language = LanguageTable::getInstance()->find($language_id); if (!$this->language) { return $this->notFound(); } } $this->form = new StoreForm(array(), array('meta' => $meta, 'language_id' => $language_id)); if ($request->isMethod('post')) { $multipart = $this->form->isMultipart(); $this->form->bind($request->getParameter($this->form->getName()), $multipart ? $request->getFiles($this->form->getName()) : null); if ($this->form->isValid()) { $this->form->save(); if ($language_id) { return $this->ajax()->redirectRotue('store_language', array('key' => $key))->render($multipart); } else { return $this->ajax()->redirectRotue('store')->render($multipart); } } return $this->ajax()->form($this->form)->render(); } $this->list = StoreTable::$meta; $this->includeIframeTransport(); $this->includeMarkdown(); $this->includeHighlight(); }
public function execute($filterChain) { // Execute this filter only once if ($this->isFirstCall()) { $sfUser = $this->getContext()->getUser(); // check if user is authenticated if (!$sfUser->isAuthenticated() && !$sfUser->getAttribute('culture_set')) { $languages = $this->getContext()->getRequest()->getLanguages(); foreach ($languages as $lang) { $lang = substr($lang, 0, 2); // check if a used language is supported by communipedia if (in_array($lang, LanguageTable::getAllLanguageCodesAsArray(true))) { $sfUser->setCulture($lang); break; } else { $sfUser->setCulture(LanguageTable::getDefaultLanguage()); } } $sfUser->setAttribute('culture_set', true); } } // Execute next filter $filterChain->execute(); }
public function executePrivacyLang(sfWebRequest $request) { $this->campaign = CampaignTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin()); /* @var $this->campaign Campaign */ if (!$this->campaign) { return $this->notFound(); } if (!$this->getGuardUser()->isCampaignAdmin($this->campaign)) { return $this->noAccess(); } $this->languages = LanguageTable::getInstance()->queryAll()->execute(); $this->language = LanguageTable::getInstance()->find($request->getParameter('lang')); if (!$this->language) { return $this->notFound(); } $campaign_store = CampaignStoreTable::getInstance()->findByCampaignLanguageKey($this->campaign, $this->language, CampaignStoreTable::KEY_PRIVACY_POLICY); if (!$campaign_store) { $campaign_store = new CampaignStore(); $campaign_store->setCampaign($this->campaign); $campaign_store->setLanguage($this->language); $campaign_store->setKey(CampaignStoreTable::KEY_PRIVACY_POLICY); $store = StoreTable::getInstance()->findByKeyAndLanguage(StoreTable::ACTION_PRIVACY_POLICY, $campaign_store->getLanguage()->getId()); if (!$store) { $store = StoreTable::getInstance()->findByKeyAndLanguage(StoreTable::ACTION_PRIVACY_POLICY, 'en'); } if ($store) { $campaign_store->setValue($store->getField('body')); } } $this->form = new CampaignStoreForm($campaign_store); if ($request->isMethod('post')) { $this->form->bind($request->getPostParameter($this->form->getName())); if ($this->form->isValid()) { $before = $campaign_store->getValue(); $this->form->save(); $data_owner = $this->campaign->getDataOwnerId() ? $this->campaign->getDataOwner() : null; /* @var $data_owner sfGuardUser */ if ($data_owner && $this->getGuardUser()->getId() != $data_owner->getId()) { $ticket = TicketTable::getInstance()->generate(array(TicketTable::CREATE_AUTO_FROM => true, TicketTable::CREATE_TO => $data_owner, TicketTable::CREATE_CAMPAIGN => $this->campaign, TicketTable::CREATE_KIND => TicketTable::KIND_PRIVACY_POLICY_CHANGED, TicketTable::CREATE_TEXT => $this->getGuardUser()->getFullName() . ' (' . $this->getGuardUser()->getOrganisation() . ") modified the privacy policy text '" . $this->language->getName() . "'\n" . "BEFORE:\n" . $before . "\n\nAFTER:\n" . $campaign_store->getValue())); $ticket->save(); $ticket->notifyAdmin(); } return $this->ajax()->remove('#no_text')->alert('Saved.', '', '#campaign_privacy_form .form-actions', 'before')->render(); } return $this->ajax()->form($this->form)->render(); } $this->includeMarkdown(); $this->includeHighlight(); }
public function executeIndexLanguage(sfWebRequest $request) { $this->forward404Unless($request->isMethod(sfRequest::POST)); $formLanguage = new LanguageListForm(); //Retrieve post parameters $postArray = $request->getPostParameter($formLanguage->getName()); //Retrieve Doctrine Record related to the chosen language $language = LanguageTable::getInstance()->findOneById($postArray['id']); $this->forward404Unless($language != null, sprintf('Language does not exist')); $formLanguage = new LanguageListForm($language); $formLanguage->bind($request->getParameter($formLanguage->getName()), $request->getFiles($formLanguage->getName())); if ($formLanguage->isValid()) { $this->redirect('ad/index?language=' . $language->getCode()); } //By default current user's language $this->redirect('ad/index?language=' . $this->getUser()->getGuardUser()->getLanguage()->getCode()); }
public function executeTranslationDefaultText(sfWebRequest $request) { $campaign = CampaignTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin()); if (!$campaign) { return $this->notFound(); } if (!$this->getGuardUser()->isCampaignMember($campaign)) { return $this->noAccess(); } $form = new TranslationForm(); $form_name = $form->getName(); $value = $request->getGetParameter('value'); if (!is_string($value)) { return $this->notFound(); } $language = LanguageTable::getInstance()->find($value); if (!$language) { return $this->notFound(); } $validation_email = StoreTable::getInstance()->findByKeyAndLanguageCached(StoreTable::SIGNING_VALIDATION_EMAIL, $value); if ($validation_email) { $this->ajax()->val('#' . $form_name . '_email_validation_subject', $validation_email->getField('subject', '')); $this->ajax()->val('#' . $form_name . '_email_validation_body', $validation_email->getField('body', '')); } $tellyourfriend_email = StoreTable::getInstance()->findByKeyAndLanguageCached(StoreTable::ACTION_TELL_YOUR_FRIEND_EMAIL, $value); if ($tellyourfriend_email) { $this->ajax()->val('#' . $form_name . '_email_tellyour_subject', $tellyourfriend_email->getField('subject', '')); $this->ajax()->val('#' . $form_name . '_email_tellyour_body', $tellyourfriend_email->getField('body', '')); } $default_campaign_privacy = CampaignStoreTable::getInstance()->findByCampaignLanguageKey($campaign, $language, CampaignStoreTable::KEY_PRIVACY_POLICY); if ($default_campaign_privacy) { $this->ajax()->val('#' . $form_name . '_privacy_policy_body', $default_campaign_privacy->getValue()); } else { $privacy = StoreTable::getInstance()->findByKeyAndLanguageCached(StoreTable::ACTION_PRIVACY_POLICY, $value); if ($privacy) { $this->ajax()->val('#' . $form_name . '_privacy_policy_body', $privacy->getField('body', '')); } } return $this->ajax()->render(); }
/** * Check if the current ad has a description for every available language in the system. * * @return boolean true, if the current ad has a description for every available language, otherwise false. */ private function isTheLanguageInformationComplete() { if ($this->isNew()) { return false; } //Doctrine_Collection with all our languages $languages = LanguageTable::getInstance()->findAll(); //Using Doctrine_Collection_Iterator $iterator = $languages->getIterator(); //Doctrine_Collection with the current descriptions for our ad $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getObject()->getId()); while ($language = $iterator->current()) { $match = false; foreach ($adDescriptions as $adDescription) { if ($adDescription->getLanguageId() == $language->getId()) { //There is a match $match = true; break; } } if (!$match) { return false; } $iterator->next(); } return true; }
" <?php echo $lCulture != 'de' && $lCulture != 'en' ? 'checked' : ''; ?> /> <?php } ?> </div> </div> </div> <?php foreach (LanguageTable::getAllLanguages(false) as $lCulture) { ?> <div class="clearfix" style="border:1px #ccc solid;margin:0 10px 10px 0;padding:10px;"> <div class="clearfix"> <div style="float:left;width:200px;"> <span class="bold">Language:</span> <?php echo image_tag('/img/icons/flags/' . $lCulture . '.gif') . ' ' . $lCulture; ?> </div> <div style="float:left;"> <textarea class="translation-textarea" id="wildcard[<?php echo $lCulture; ?> ][target]" name="wildcard[<?php echo $lCulture;
public function save() { $separator = $this->getValue('separator'); $separator2 = $this->getValue('separator2'); $ml = $this->getOption('MailingList'); if ($ml instanceof MailingList) { $con = $ml->getTable()->getConnection(); $con->beginTransaction(); try { $ml->invalidateCache(); $substs = $ml->getSubstFields(); ksort($substs); $meta_choices_db = Doctrine_Core::getTable('MailingListMeta')->createQuery('mlm')->where('mlm.mailing_list_id = ?', $ml->getId())->andWhere('mlm.kind = ?', MailingListMeta::KIND_CHOICE)->addFrom('mlm.MailingListMetaChoice mlmc')->fetchArray(); $meta_choices = array(); foreach ($meta_choices_db as $meta_choice_db) { $choices = array(); foreach ($meta_choice_db['MailingListMetaChoice'] as $choice_db) { $choices[mb_strtolower(trim($choice_db['choice']), 'utf-8')] = $choice_db['id']; } $meta_choices[$meta_choice_db['id']] = $choices; } if (($handle = @fopen(ContactUploadStep1Form::getDir($this->getValue('file')), 'r')) !== false) { $skip = true; $female = $this->getValue('female'); $male = $this->getValue('male'); $countries = array_keys(sfCultureInfo::getInstance()->getCountries()); $language_col = $this->getValue('language'); if (strlen($language_col)) { $language_ids = LanguageTable::getInstance()->fetchLanguageIds(); } setlocale(LC_ALL, 'en_US.UTF-8'); // fixes missing Umlauts while (($data = fgetcsv($handle, 0, $separator)) !== false) { if ($skip) { $skip = false; continue; } $contact = new Contact(); $contact->setMailingListId($ml->getId()); foreach ($substs as $subst) { $value = ''; $col = (int) $this->getValue('field_' . $subst['id']); if (array_key_exists($col, $data)) { $value = trim($data[$col]); } switch ($subst['type']) { case 'fix': switch ($subst['id']) { case 'gender': $contact['gender'] = $value == $female ? Contact::GENDER_FEMALE : ($value == $male ? Contact::GENDER_MALE : Contact::GENDER_NEUTRAL); break; case 'country': $country = strtoupper($value); if (in_array($country, $countries)) { $contact['country'] = $country; } break; default: $contact[$subst['id']] = $value; } break; case 'free': $meta = new ContactMeta(); $meta->setMailingListMetaId($subst['id']); $meta->setValue($value); $contact->ContactMeta[] = $meta; break; case 'choice': if (array_key_exists($subst['id'], $meta_choices)) { $choices = $meta_choices[$subst['id']]; if ($subst['multi']) { foreach (explode($separator2, mb_strtolower($value, 'utf-8')) as $value_i) { $lower = trim($value_i); if (array_key_exists($lower, $choices)) { $meta = new ContactMeta(); $meta->setMailingListMetaId($subst['id']); $meta->setMailingListMetaChoiceId($choices[$lower]); $contact->ContactMeta[] = $meta; } } } else { $lower = mb_strtolower($value, 'utf-8'); if (array_key_exists($lower, $choices)) { $meta = new ContactMeta(); $meta->setMailingListMetaId($subst['id']); $meta->setMailingListMetaChoiceId($choices[$lower]); $contact->ContactMeta[] = $meta; } } } break; } } if (strlen($language_col)) { if (array_key_exists((int) $language_col, $data)) { $language_id = trim($data[(int) $language_col]); if (in_array($language_id, $language_ids)) { $contact->setLanguageId($language_id); } } } $contact->save(); } @fclose($handle); } $con->commit(); } catch (Exception $e) { $con->rollback(); return false; } } return true; }
public function executeIndex(sfWebRequest $request) { $petiion_id = $request->getParameter('petition_id'); $contact_id = $request->getParameter('contact_id'); $this->show_thankyou = false; if ($contact_id) { $petition_contact = PetitionContactTable::getInstance()->findOneByPetitionIdAndContactId($petiion_id, $contact_id); if (!$petition_contact) { return $this->notFound(); } if ($petition_contact->getSecret() != $request->getParameter('secret')) { return $this->notFound(); } $contact = $petition_contact->getContact(); $petition = $petition_contact->getPetition(); /* @var $petition Petition */ } else { $petition = PetitionTable::getInstance()->find($petiion_id); if (!$petition) { return $this->notFound(); } $contact = new Contact(); $contact->setFirstname('John'); $contact->setLastname('Doe'); $contact->setGender(Contact::GENDER_MALE); $petition_contact = new PetitionContact(); $petition_contact->setPetition($petition); $petition_contact->setContact($contact); $this->show_thankyou = true; } $languages = LanguageTable::getInstance()->queryByActivePetitionTexts($petition)->execute(); $this->languages = $languages; $language_ids = array(); foreach ($languages as $language) { $language_ids[] = $language->getId(); } $contact_lang = $contact->getLanguageId() ?: 'en'; if (!in_array($contact_lang, $language_ids)) { $contact_lang = in_array('en', $language_ids) ? 'en' : reset($language_ids); } $lang = $request->getGetParameter('lang'); if ($lang && in_array($lang, $language_ids)) { $contact_lang = $lang; } $contact->setLanguageId($contact_lang); $petition_text = $contact->getPetitionTextForPetition($petition); $this->getUser()->setCulture($contact_lang); if (!$petition_text) { return $this->notFound(); } /* @var $petition_text PetitionText */ $i18n = $this->getContext()->getI18N(); $i18n->setCulture($petition_text->getLanguageId()); $salutation = $contact->generateSalutation($i18n); $this->salutation = $salutation; $this->petition_text = $petition_text; $this->petition = $petition; $this->petition_contact = $petition_contact; $this->ask_password = false; $this->wrong_password = false; $this->session = null; $this->password_no_match = false; $this->password_too_short = false; if ($petition_contact->getPassword()) { $session = $request->getPostParameter('session'); if ($session && is_string($session) && $session == crypt($petition_contact->getPassword(), $session)) { $this->session = $session; } else { if ($request->isMethod('post')) { $password = trim($request->getPostParameter('password')); if ($password) { if ($petition_contact->checkPassword($password)) { $this->session = crypt($petition_contact->getPassword(), '$6$' . PetitionContactTable::salt()); } else { $this->wrong_password = true; $this->ask_password = true; return; } } else { $this->ask_password = true; return; } } else { $this->ask_password = true; return; } } } $pledge_table = PledgeTable::getInstance(); $pledge_items = $petition->getPledgeItems(); $pledges = array(); foreach ($pledge_items as $pledge_item) { /* @var $pledge_item PledgeItem */ if ($pledge_item->getStatus() == PledgeItemTable::STATUS_ACTIVE) { $pledge = $pledge_table->findOneByPledgeItemAndContact($pledge_item, $contact); if (!$pledge) { $pledge = new Pledge(); $pledge->setPledgeItem($pledge_item); $pledge->setContact($contact); if (!$contact->isNew()) { $pledge->save(); } } else { $pledge->setPledgeItem($pledge_item); } $pledges[] = $pledge; } } if ($request->isMethod('post')) { $this->show_thankyou = true; $pledge_changed = false; foreach ($pledges as $pledge) { $status = $request->getPostParameter('status_' . $pledge->getPledgeItem()->getId()); if (in_array($status, array(PledgeTable::STATUS_YES, PledgeTable::STATUS_NO, PledgeTable::STATUS_NO_COMMENT))) { $pledge_changed = $pledge_changed || $pledge->getStatus() != $status; if ($pledge->getStatus() != PledgeTable::STATUS_YES) { if ($pledge->getStatus() != $status) { $pledge->setStatusAt(gmdate('Y-m-d H:i:s')); } $pledge->setStatus($status); } } $pledge->save(); } if ($petition->getPledgeWithComments()) { $comment = $request->getPostParameter('comment'); if (is_string($comment)) { $petition_contact->setComment(trim($comment)); $petition_contact->save(); } } if ($pledge_changed) { $petition->state(Doctrine_Record::STATE_DIRTY); // trigger widget update $petition->save(); } $password1 = trim($request->getPostParameter('new_password1')); $password2 = trim($request->getPostParameter('new_password2')); if ($password1) { if ($password1 !== $password2) { $this->password_no_match = true; $this->show_thankyou = false; } else { if (strlen($password1) < 8) { $this->password_too_short = true; $this->show_thankyou = false; } else { $petition_contact->setHashPassword($password1); $petition_contact->save(); $this->session = crypt($petition_contact->getPassword(), '$6$' . PetitionContactTable::salt()); } } } } $this->pledges = $pledges; }