function __($stringId) { if (!defined('PLANCAKE_PUBLIC_RELEASE')) { $lang = PcLanguagePeer::getUserPreferredLanguage()->getId(); $key = ''; if ($cache = PcCache::getInstance()) { $key = PcCache::generateKeyForTranslation($lang, $stringId); if ($cache->has($key)) { return $cache->get($key); } } $translation = PcTranslationPeer::retrieveByPK($lang, $stringId); if (!is_object($translation) || !strlen(trim($translation->getString())) > 0) { $translation = PcTranslationPeer::retrieveByPK(SfConfig::get('app_site_defaultLang'), $stringId); } if (!$translation) { throw new Exception("Couldn't find the string {$stringId} for the language {$lang}"); } $ret = $translation->getString(); if ($cache) { $cache->set($key, $ret); } } else { global $pc_lang; if (!array_key_exists($stringId, $pc_lang)) { throw new Exception("Couldn't find the string {$stringId}"); } $ret = $pc_lang[$stringId]; } return $ret; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $lang = PcLanguagePeer::getUserPreferredLanguage()->getId(); if (!$lang) { $lang = SfConfig::get('app_site_defaultLang'); } $this->lang = $lang; $this->baseUrl = sfConfig::get('app_site_url') . (sfConfig::get('sf_environment') == 'prod' ? '' : '/') . sfConfig::get('app_publicApp_frontController'); if (defined('PLANCAKE_PUBLIC_RELEASE')) { $this->baseUrl = 'http://www.plancake.com'; } $userCulture = $this->getUser()->getCulture(); $this->cultureUrlPart = ''; if ($userCulture != SfConfig::get('app_site_defaultLang')) { $this->cultureUrlPart = '/' . $userCulture; } // this is a "backdoor" to avoid redirection: just append ?redirect=no to the URL if ($request->getParameter('redirect') == 'no') { return; } // if the user is authenticated, they will be redirected // to their account if ($this->getUser()->isAuthenticated()) { $this->redirect('/' . sfConfig::get('app_accountApp_frontController')); } }
/** * @return PcLanguage */ public static function getUserPreferredLanguage() { $c = new Criteria(); $c->add(self::ID, strtolower(sfContext::getInstance()->getUser()->getCulture())); $lang = self::doSelectOne($c); if (!is_object($lang)) { $lang = PcLanguagePeer::retrieveByPk(SfConfig::get('app_site_defaultLang')); } return $lang; }
public function executeSendFeedback(sfWebRequest $request) { $user = PcUserPeer::getLoggedInUser(); $message = $request->getParameter('message'); $to = sfConfig::get('app_emailAddress_contact'); $subject = "Submitted feedback"; if (PcLanguagePeer::getUserPreferredLanguage()->getId() == 'it') { $subject = 'Richiesta da box'; } // we need to add a 'random' code otherwise GMail groups all of them together $subject .= ' ' . date('YmdHis'); $message = $message . "\n ----- \n" . $_SERVER['HTTP_USER_AGENT']; PcUtils::sendEmail($to, $subject, $message, $to, PcUserPeer::getLoggedInUser()->getEmail()); return $this->renderDefault(); }
public static function getWebAppStrings() { $lang = PcLanguagePeer::getUserPreferredLanguage()->getId(); $c = new Criteria(); $c->add(PcStringPeer::CATEGORY_ID, array(115, 119), Criteria::NOT_IN); // Settings && GCal integration $c->add(PcStringPeer::IS_ARCHIVED, 0); $c->addJoin(PcStringPeer::CATEGORY_ID, PcStringCategoryPeer::ID); $c->add(PcStringCategoryPeer::IN_ACCOUNT, 1); $stringsFromAccount = PcStringPeer::doSelect($c); $c = new Criteria(); $c->add(PcStringPeer::CATEGORY_ID, 2); // General $c->add(PcStringPeer::IS_ARCHIVED, 0); $c->addJoin(PcStringPeer::CATEGORY_ID, PcStringCategoryPeer::ID); $c->add(PcStringCategoryPeer::IN_ACCOUNT, 0); $c->add(PcStringCategoryPeer::IN_MISC, 0); return array_merge($stringsFromAccount, PcStringPeer::doSelect($c)); }
public function execute($filterChain) { $context = $this->getContext(); $request = $context->getRequest(); $user = $context->getUser(); $availableLangs = PcLanguagePeer::getAvailableLanguageAbbreviations(); if ($preferredLang = $request->getParameter('pc_preferred_lang')) { $loggedInUser = PcUserPeer::getLoggedInUser(); if ($loggedInUser) { if (in_array($preferredLang, $availableLangs)) { $user->setCulture($preferredLang); $loggedInUser->setPreferredLanguage($preferredLang)->save(); } } } // fallback to default language if (!$user->getCulture()) { $user->setCulture(SfConfig::get('app_site_defaultLang')); } $filterChain->execute(); }
public function execute($filterChain) { $context = $this->getContext(); $request = $context->getRequest(); $user = $context->getUser(); $availableLangs = PcLanguagePeer::getAvailableLanguageAbbreviations(); $preferredLang = $request->getParameter('pc_preferred_lang'); sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url')); $loggedInUser = PcUserPeer::getLoggedInUser(); if ($loggedInUser && !$preferredLang) { $user->setCulture($loggedInUser->getPreferredLanguage()); } else { if ($preferredLang) { if (in_array($preferredLang, $availableLangs)) { $user->setCulture($preferredLang); if ($loggedInUser) { $loggedInUser->setPreferredLanguage($preferredLang)->save(); } } } else { if (!$user->getAttribute('after_user_first_request')) { $culture = strtolower($request->getPreferredCulture($availableLangs)); $user->setCulture($culture); if ($context->getModuleName() == 'homepage' && $context->getActionName() == 'index') { if ($culture != SfConfig::get('app_site_defaultLang')) { header('Location: ' . url_for('@localized_homepage', true)); } } $user->setAttribute('after_user_first_request', true); } } } // fallback to default language if (!$user->getCulture()) { $user->setCulture(SfConfig::get('app_site_defaultLang')); } $filterChain->execute(); }
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <?php include_http_metas(); ?> <?php include_metas(); ?> <title> <?php include_slot('title'); ?> </title> <?php if (PcLanguagePeer::isUserPreferredLanguageRTL()) { ?> <style> input, textarea { direction: rtl; } </style> <?php } ?> <?php include_component('misc', 'localizedStrings'); ?>
/** * Get the associated PcLanguage object * * @param PropelPDO Optional Connection object. * @return PcLanguage The associated PcLanguage object. * @throws PropelException */ public function getPcLanguage(PropelPDO $con = null) { if ($this->aPcLanguage === null && ($this->language_id !== "" && $this->language_id !== null)) { $this->aPcLanguage = PcLanguagePeer::retrieveByPk($this->language_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPcLanguage->addPcTranslations($this); */ } return $this->aPcLanguage; }
/** * Selects a collection of PcTranslator objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of PcTranslator objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } PcTranslatorPeer::addSelectColumns($criteria); $startcol2 = PcTranslatorPeer::NUM_COLUMNS - PcTranslatorPeer::NUM_LAZY_LOAD_COLUMNS; PcLanguagePeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (PcLanguagePeer::NUM_COLUMNS - PcLanguagePeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(PcTranslatorPeer::LANGUAGE_ID, PcLanguagePeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BasePcTranslatorPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = PcTranslatorPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = PcTranslatorPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = PcTranslatorPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); PcTranslatorPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined PcLanguage rows $key2 = PcLanguagePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = PcLanguagePeer::getInstanceFromPool($key2); if (!$obj2) { $cls = PcLanguagePeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); PcLanguagePeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (PcTranslator) to the collection in $obj2 (PcLanguage) $obj2->addPcTranslator($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function executeLangSelection(sfWebRequest $request) { $this->languages = PcLanguagePeer::getAvailableLanguagesPreferredFirst(); $this->langCount = count($this->languages); $this->preferredLanguage = PcLanguagePeer::getUserPreferredLanguage(); }
public static function getMainNavigationKey() { return PcLanguagePeer::getUserPreferredLanguage()->getId() . '-' . PcUserPeer::getLoggedInUser()->getId(); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = PcLanguagePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setSortOrder($arr[$keys[2]]); } }
/** * Register a new user * * @param string $email - the email address * @param string $password - the plain password (no encryption) * @param string $lang - if it is null or empty, the language will be detected from the header of the request * @param string $preferredLang - this should be a 2-char abbreviation of the lang the user wants, * among the ones in the main app.yml config file * @param string $tzLabel - a timezone label as in the PcTimezone db table * @param integer $dstOn (1 or 0) - whether or not the dst for the user is on * @param boolen $joinNewsletter(=false) - whether the user decided to join our newsletter * @param boolen $sendActivationEmail(=true) - whether to send the activation email * @return boolean|PcUser false is a user with that email already exists, the PcUser object otherwise */ public static function registerNewUser($email, $password, $lang, $preferredLang, $tzLabel, $dstOn, $joinNewsletter = false, $sendActivationEmail = true) { if (self::emailExist($email)) { return false; } $newUser = new PcUser(); $newUser->setEmail($email); $newUser->setPassword($password); $newUser->setAwaitingActivation(1); if ($joinNewsletter) { $newUser->setNewsletter(1); } $newUser->save(); // Dealing with timezone $newUser->setDstActive($dstOn); $c = new Criteria(); $c->add(PcTimezonePeer::LABEL, $tzLabel, Criteria::EQUAL); $timezone = PcTimezonePeer::doSelectOne($c); if (!is_object($timezone)) { // set to a default one $timezone = PcTimezonePeer::retrieveByPK(21); } $newUser->setTimezoneId($timezone->getId()); // Dealing with formats // _ time format: the countries with the majority of our users are using the // 12H format, thus we can leave the default // _ for the date format we check whether they are in USA // _ for the first day of the week, we check whether they are in USA $dateFormatId = 3; $weekStart = 1; // from Monday $tzOffset = $timezone->getOffset(); if ($tzOffset <= -300 && $tzOffset >= -450) { $dateFormatId = 4; $weekStart = 0; // from Sunday } $newUser->setDateFormat($dateFormatId); $newUser->setWeekStart($weekStart); if ($lang != null && $lang !== '') { $newUser->setLanguage($lang); } else { $newUser->setLanguage(PcUtils::getVisitorAcceptLanguage()); } $availableLangs = PcLanguagePeer::getAvailableLanguageAbbreviations(); if (in_array($preferredLang, $availableLangs)) { $newUser->setPreferredLanguage($preferredLang); } else { $newUser->setPreferredLanguage(SfConfig::get('app_site_defaultLang')); } $newUser->setIpAddress(PcUtils::getVisitorIPAddress()); if ($sessionEntryPoint = sfContext::getInstance()->getUser()->getAttribute('session_entry_point')) { $newUser->setSessionEntryPoint($sessionEntryPoint); } if ($sessionReferral = sfContext::getInstance()->getUser()->getAttribute('session_referral')) { $newUser->setSessionReferral($sessionReferral); } $newUser->save(); // Creating system lists $inboxList = new PcList(); $inboxList->setIsInbox(1)->setTitle(__('ACCOUNT_LISTS_INBOX'))->setCreator($newUser)->save(); $todoList = new PcList(); $todoList->setIsTodo(1)->setTitle(__('ACCOUNT_LISTS_TODO'))->setCreator($newUser)->save(); // Creating default contexts $context = new PcUsersContexts(); $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_HOME'))->save(); $context = new PcUsersContexts(); $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_ERRANDS'))->save(); $context = new PcUsersContexts(); $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_COMPUTER'))->save(); // Creating some tasks for the inbox $newUser->addToInbox(__('ACCOUNT_MISC_WELCOME_TASK')); // creating Plancake email address $newUser->generateAndStorePlancakeEmailAddress(); // I need to use a token for the activation of their account $token = ''; $c = new Criteria(); $c->add(PcActivationTokenPeer::USER_ID, $newUser->getId(), Criteria::EQUAL); $tokenEntry = PcActivationTokenPeer::doSelectOne($c); if (is_object($tokenEntry)) { $token = $tokenEntry->getToken(); } else { $secret = sfConfig::get('app_registration_secret'); // token doesn't need to be 32-char long. It is better to keep it short // so there will be less chance the email client will break the link into 2 lines $token = substr(md5($newUser->getId() . $secret . time()), 0, 14); $tokenEntry = new PcActivationToken(); $tokenEntry->setUserId($newUser->getId()); $tokenEntry->setToken($token); $tokenEntry->save(); } // now we can send the email if ($sendActivationEmail) { $link = sfContext::getInstance()->getController()->genUrl('@activation?t=' . $token, true); $from = sfConfig::get('app_emailAddress_contact'); $subject = 'Plancake - ' . __('WEBSITE_REGISTRATION_EMAIL_SUBJECT'); $body = sprintf(__('WEBSITE_REGISTRATION_EMAIL_BODY'), $link); PcUtils::sendEmail($email, $subject, $body, $from); } $newUser->refreshLatestBlogAccess(); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($newUser, 'user.sign_up', array('user' => $newUser, 'plainPassword' => $password))); return $newUser; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(PcLanguagePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(PcLanguagePeer::DATABASE_NAME); $criteria->add(PcLanguagePeer::ID, $pks, Criteria::IN); $objs = PcLanguagePeer::doSelect($criteria, $con); } return $objs; }