Ejemplo n.º 1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Also check owner (see #126)
     if (($objOrder = Order::findOneBy('uniqid', (string) \Input::get('uid'))) === null || FE_USER_LOGGED_IN === true && $objOrder->member > 0 && \FrontendUser::getInstance()->id != $objOrder->member) {
         $this->Template = new \Isotope\Template('mod_message');
         $this->Template->type = 'error';
         $this->Template->message = $GLOBALS['TL_LANG']['ERR']['orderNotFound'];
         return;
     }
     // Order belongs to a member but not logged in
     if (TL_MODE == 'FE' && $this->iso_loginRequired && $objOrder->member > 0 && FE_USER_LOGGED_IN !== true) {
         global $objPage;
         $objHandler = new $GLOBALS['TL_PTY']['error_403']();
         $objHandler->generate($objPage->id);
         exit;
     }
     Isotope::setConfig($objOrder->getRelated('config_id'));
     $objTemplate = new \Isotope\Template($this->iso_collectionTpl);
     $objTemplate->linkProducts = true;
     $objOrder->addToTemplate($objTemplate, array('gallery' => $this->iso_gallery, 'sorting' => $objOrder->getItemsSortingCallable($this->iso_orderCollectionBy)));
     $this->Template->collection = $objOrder;
     $this->Template->products = $objTemplate->parse();
     $this->Template->info = deserialize($objOrder->checkout_info, true);
     $this->Template->date = Format::date($objOrder->locked);
     $this->Template->time = Format::time($objOrder->locked);
     $this->Template->datim = Format::datim($objOrder->locked);
     $this->Template->orderDetailsHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['orderDetailsHeadline'], $objOrder->document_number, $this->Template->datim);
     $this->Template->orderStatus = sprintf($GLOBALS['TL_LANG']['MSC']['orderStatusHeadline'], $objOrder->getStatusLabel());
     $this->Template->orderStatusKey = $objOrder->getStatusAlias();
 }
 protected function runBeforeTemplateParsing($objTemplate, $arrItem)
 {
     $objTemplate->ago = DateUtil::getTimeElapsed($arrItem['raw']['date']);
     $objTemplate->commentCount = \CommentsModel::countPublishedBySourceAndParent('tl_news', $arrItem['fields']['id']);
     $objTemplate->isAuthor = $arrItem['raw']['memberAuthor'] == \FrontendUser::getInstance()->id;
     $this->imgSize = deserialize($this->imgSize, true);
     if ($objTemplate->isAuthor && !$arrItem['raw']['published']) {
         $objTemplate->unpublished = true;
     }
     // media
     $strMedia = '';
     if ($arrItem['raw']['mediaType'] == 'video') {
         $arrItem['fields']['addYouTube'] = true;
         $arrItem['fields']['youtube'] = preg_replace('@.*watch\\?v=([^&]+).*@i', '$1', $arrItem['fields']['pinBoardYouTube']);
         $objYouTube = YouTubeVideo::getInstance()->setData($arrItem['fields']);
         $strMedia = $objYouTube->getCachedYouTubePreviewImage();
     } elseif ($arrItem['fields']['pinBoardImage']) {
         $strMedia = $arrItem['fields']['pinBoardImage'];
     }
     if ($strMedia) {
         $objTemplate->media = \Image::get($strMedia, $this->imgSize[0], $this->imgSize[1], $this->imgSize[2]);
         $arrSize = getimagesize(urldecode(TL_ROOT . '/' . $objTemplate->media));
         if (count($arrSize) > 1) {
             $objTemplate->imgSizeParsed = 'width="' . $arrSize[0] . '" height="' . $arrSize[1] . '"';
         }
     }
 }
Ejemplo n.º 3
0
 public function createNew($email)
 {
     $newUser = new FrontendUser();
     $newUser->username = $email;
     $newUser->email = $email;
     $password = PasswordGenerator::createSimple();
     $newUser->password = $password;
     try {
         if ($newUser->save()) {
             EmailManager::sendUserInfo($newUser, $password);
         }
     } catch (Exception $e) {
         return $this->checkIfExists($email);
     }
     return $newUser;
 }
 public static function checkPermissionForProtectedHomeDirs($strFile)
 {
     $strUuid = \Config::get('protectedHomeDirRoot');
     if (!$strFile) {
         return;
     }
     if ($strUuid && ($strProtectedHomeDirRootPath = \HeimrichHannot\HastePlus\Files::getPathFromUuid($strUuid)) !== null) {
         // check only if path inside the protected root dir
         if (StringUtil::startsWith($strFile, $strProtectedHomeDirRootPath)) {
             if (FE_USER_LOGGED_IN) {
                 if (($objFrontendUser = \FrontendUser::getInstance()) !== null) {
                     if (\Config::get('allowAccessByMemberId') && $objFrontendUser->assignProtectedDir && $objFrontendUser->protectedHomeDir) {
                         $strProtectedHomeDirMemberRootPath = Files::getPathFromUuid($objFrontendUser->protectedHomeDir);
                         // fe user id = dir owner member id
                         if (StringUtil::startsWith($strFile, $strProtectedHomeDirMemberRootPath)) {
                             return;
                         }
                     }
                     if (\Config::get('allowAccessByMemberGroups')) {
                         $arrAllowedGroups = deserialize(\Config::get('allowedMemberGroups'), true);
                         if (array_intersect(deserialize($objFrontendUser->groups, true), $arrAllowedGroups)) {
                             return;
                         }
                     }
                 }
             }
             $intNoAccessPage = \Config::get('jumpToNoAccess');
             if ($intNoAccessPage && ($objPageJumpTo = \PageModel::findByPk($intNoAccessPage)) !== null) {
                 \Controller::redirect(\Controller::generateFrontendUrl($objPageJumpTo->row()));
             } else {
                 die($GLOBALS['TL_LANG']['MSC']['noAccessDownload']);
             }
         }
     }
 }
Ejemplo n.º 5
0
 protected function __construct()
 {
     $this->strIp = !\Config::get('disableIpCheck') ? \Environment::get('ip') : '';
     $this->strName = FE_USER_LOGGED_IN ? WATCHLIST_SESSION_FE : WATCHLIST_SESSION_BE;
     $this->strHash = sha1(session_id() . $this->strIp . $this->strName);
     if (($this->objModel = WatchlistModel::findByHashAndName($this->strHash, $this->strName)) === null) {
         $this->objModel = new WatchlistModel();
         $this->objModel->hash = $this->strHash;
         $this->objModel->name = $this->strName;
         $this->objModel->tstamp = time();
         $this->objModel->pid = \FrontendUser::getInstance()->id;
         $this->objModel->sessionID = session_id();
         $this->objModel->ip = $this->strIp;
         $this->objModel->save();
     }
     $objItems = WatchlistItemModel::findBy('pid', $this->objModel->id);
     if ($objItems !== null) {
         while ($objItems->next()) {
             // set key by unique uuid
             $strKey = \String::binToUuid($objItems->uuid);
             $this->arrItems[$strKey] = $objItems->current();
             $this->arrIds[] = $strKey;
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Constructor
  */
 public function __construct()
 {
     // If we are in the Backend-Mode use the BackendUser.
     if (TL_MODE == 'FE') {
         $this->user = \FrontendUser::getInstance();
     } else {
         $this->user = \BackendUser::getInstance();
     }
     // Language
     \Controller::loadLanguageFile("default");
     \Controller::loadLanguageFile('tl_synccto_clients');
     // Instance a list for regex from the blacklist for folders.
     $this->arrPreparedBlacklistFolder = array();
     foreach ($this->getBlacklistFolder() as $key => $value) {
         $this->arrPreparedBlacklistFolder[$key] = str_replace($this->arrSearch, $this->arrReplace, $value);
     }
     // Instance a list for regex from the blacklist for files.
     $this->arrPreparedBlacklistFiles = array();
     foreach ($this->getBlacklistFile() as $key => $value) {
         $this->arrPreparedBlacklistFiles[$key] = str_replace($this->arrSearch, $this->arrReplace, $value);
     }
     // Instance a list for regex from the hidden table list.
     $this->arrPreparedHiddenTablePlaceholder = array();
     foreach ($this->getHiddenTablePlaceholder() as $key => $value) {
         $this->arrPreparedHiddenTablePlaceholder[$key] = str_replace($this->arrSearch, $this->arrReplace, $value);
     }
     // Replace some elements in TL_ROOT for regex.
     $this->strPreparedTlRoot = str_replace('\\', '\\\\', TL_ROOT);
 }
Ejemplo n.º 7
0
 protected function buildFileDir($objEntity = null)
 {
     if ($this->fileDir && ($objFolder = \FilesModel::findByUuid($this->fileDir))) {
         $objMember = \FrontendUser::getInstance();
         $strDir = $objFolder->path;
         if ($this->useHomeDir && FE_USER_LOGGED_IN && $objMember->assignDir && $objMember->homeDir) {
             $strDir = Files::getPathFromUuid($objMember->homeDir);
         }
         if (in_array('protected_homedirs', \ModuleLoader::getActive())) {
             if ($this->useProtectedHomeDir && $objMember->assignProtectedDir && $objMember->protectedHomeDir) {
                 $strDir = Files::getPathFromUuid($objMember->protectedHomeDir);
             }
         }
         if ($this->fileSubDirName) {
             $strDir .= '/' . $this->fileSubDirName;
         }
         if (isset($GLOBALS['TL_HOOKS']['exporter_modifyFileDir']) && is_array($GLOBALS['TL_HOOKS']['exporter_modifyFileDir'])) {
             foreach ($GLOBALS['TL_HOOKS']['exporter_modifyFileDir'] as $callback) {
                 $objCallback = \System::importStatic($callback[0]);
                 $strFixedDir = $objCallback->{$callback}[1]($strDir, $this);
                 $strDir = $strFixedDir ?: $strDir;
             }
         }
         return $strDir;
     }
     throw new \Exception('No exporter fileDir defined!');
 }
Ejemplo n.º 8
0
 /**
  * Run the controller
  */
 public function run()
 {
     $strFile = \Input::get('file', true);
     if ($strFile != '') {
         // Make sure there are no attempts to hack the file system
         if (preg_match('@^\\.+@i', $strFile) || preg_match('@\\.+/@i', $strFile) || preg_match('@(://)+@i', $strFile)) {
             header('HTTP/1.1 404 Not Found');
             die('Invalid file name');
         }
         // Limit downloads to the files directory
         if (!preg_match('@^' . preg_quote(\Config::get('uploadPath'), '@') . '@i', $strFile)) {
             header('HTTP/1.1 404 Not Found');
             die('Invalid path');
         }
         // Check whether the file exists
         if (!is_file(TL_ROOT . '/' . $strFile)) {
             header('HTTP/1.1 404 Not Found');
             die('File not found');
         }
         // find the path in the database
         if (($objFile = \FilesModel::findOneByPath($strFile)) !== null) {
             // authenticate the frontend user
             \FrontendUser::getInstance()->authenticate();
             // check if file is protected
             if (!\Controller::isVisibleElement($objFile)) {
                 $objHandler = new $GLOBALS['TL_PTY']['error_403']();
                 $objHandler->generate($strFile);
             } elseif ($objFile->pid) {
                 // check if parent folders are proteced
                 do {
                     $objFile = \FilesModel::findById($objFile->pid);
                     if (!\Controller::isVisibleElement($objFile)) {
                         $objHandler = new $GLOBALS['TL_PTY']['error_403']();
                         $objHandler->generate($strFile);
                     }
                 } while ($objFile->pid);
             }
         }
         // get the file
         $objFile = new \File($strFile);
         // Make sure no output buffer is active
         // @see http://ch2.php.net/manual/en/function.fpassthru.php#74080
         while (@ob_end_clean()) {
         }
         // Prevent session locking (see #2804)
         session_write_close();
         // Disable zlib.output_compression (see #6717)
         @ini_set('zlib.output_compression', 'Off');
         // Set headers
         header('Content-Type: ' . $objFile->mime);
         header('Content-Length: ' . $objFile->filesize);
         // Disable maximum execution time
         @ini_set('max_execution_time', 0);
         // Output the file
         readfile(TL_ROOT . '/' . $objFile->path);
     }
     // Stop the script (see #4565)
     exit;
 }
 public function getGlobals()
 {
     $globals = array('REQUEST_TOKEN' => REQUEST_TOKEN, '_session' => new ContaoTwigGlobalAccessObject('_SESSION'), '_lang' => new ContaoTwigGlobalAccessObject('TL_LANG'), '_dca' => new ContaoTwigGlobalAccessObject('TL_DCA'), '_config' => new ContaoTwigGlobalAccessObject('TL_CONFIG'), '_env' => new ContaoTwigEnvironmentAccessObject(), '_referer' => new ContaoTwigRefererAccessObject(), '_db' => Database::getInstance(), '_page' => $GLOBALS['objPage'], '_member' => TL_MODE == 'FE' && FE_USER_LOGGED_IN ? FrontendUser::getInstance() : false, '_user' => TL_MODE == 'BE' && BE_USER_LOGGED_IN ? BackendUser::getInstance() : false);
     if (version_compare(VERSION, '3.1', '>=')) {
         $globals['REFERER_ID'] = TL_REFERER_ID;
     }
     return $globals;
 }
 /**
  * @param IsotopeProductCollection $objOrder
  * @param \Module $objModule
  * @return mixed
  */
 public function processPayment(IsotopeProductCollection $objOrder, \Module $objModule)
 {
     // Get user's SEPA account
     $user = \FrontendUser::getInstance();
     // Save to order
     $objOrder->payment_data = array('iso_sepa_iban' => $user->iso_sepa_iban, 'iso_sepa_bic' => $user->iso_sepa_bic, 'iso_sepa_accountholder' => $user->iso_sepa_accountholder, 'iso_sepa_mandate' => $user->iso_sepa_mandate, 'iso_sepa_date_of_issue' => $user->iso_sepa_date_of_issue);
     return parent::processPayment($objOrder, $objModule);
 }
Ejemplo n.º 11
0
 /**
  * Get the current Contao user.
  *
  * @return \BackendUser|\FrontendUser|null
  */
 public static function getUser()
 {
     if (TL_MODE == 'BE') {
         return \BackendUser::getInstance();
     } elseif (TL_MODE == 'FE') {
         return \FrontendUser::getInstance();
     }
     return null;
 }
Ejemplo n.º 12
0
 /**
  * Returns the proper user object for the current context.
  *
  * @return BackendUser|FrontendUser|null the BackendUser when TL_MODE == 'BE', the FrontendUser when TL_MODE == 'FE' or null otherwise
  */
 protected static function getUser()
 {
     if (TL_MODE == 'BE') {
         return BackendUser::getInstance();
     } else {
         if (TL_MODE == 'FE') {
             return FrontendUser::getInstance();
         }
     }
     return null;
 }
Ejemplo n.º 13
0
 /**
  * Get the page cache service.
  *
  * @return PageCache
  */
 public function service()
 {
     if ($this->service === null) {
         // Create the Contao stack. Why isn't is part of system/initialize.php?
         if (TL_MODE === 'FE') {
             \FrontendUser::getInstance();
         } else {
             \BackendUser::getInstance();
         }
         $this->service = new PageCache(Database::getInstance(), Files::getInstance());
     }
     return $this->service;
 }
 /**
  * {@inheritdoc}
  */
 public function matchItem(ItemInterface $item)
 {
     if ($item->getType() != 'article') {
         return true;
     }
     if (!FE_USER_LOGGED_IN) {
         return false;
     }
     $articleGroups = $item->getExtra('groups');
     $memberGroups = \FrontendUser::getInstance()->groups;
     $groups = array_intersect($memberGroups, $articleGroups);
     return (bool) count($groups);
 }
Ejemplo n.º 15
0
 /**
  * Return true or false depending on if shipping method is available
  * @return bool
  * @todo must check availability for a specific product collection (and not hardcoded to the current cart)
  */
 public function isAvailable()
 {
     if (!$this->enabled && BE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->guests && FE_USER_LOGGED_IN === true || $this->protected && FE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->protected) {
         $arrGroups = deserialize($this->groups);
         if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, \FrontendUser::getInstance()->groups))) {
             return false;
         }
     }
     if ($this->minimum_total > 0 && $this->minimum_total > Isotope::getCart()->getSubtotal() || $this->maximum_total > 0 && $this->maximum_total < Isotope::getCart()->getSubtotal()) {
         return false;
     }
     $objScale = Isotope::getCart()->addToScale();
     if (($minWeight = Weight::createFromTimePeriod($this->minimum_weight)) !== null && $objScale->isLessThan($minWeight)) {
         return false;
     }
     if (($maxWeight = Weight::createFromTimePeriod($this->maximum_weight)) !== null && $objScale->isMoreThan($maxWeight)) {
         return false;
     }
     $objAddress = Isotope::getCart()->getShippingAddress();
     $arrCountries = deserialize($this->countries);
     if (is_array($arrCountries) && !empty($arrCountries) && !in_array($objAddress->country, $arrCountries)) {
         return false;
     }
     $arrSubdivisions = deserialize($this->subdivisions);
     if (is_array($arrSubdivisions) && !empty($arrSubdivisions) && !in_array($objAddress->subdivision, $arrSubdivisions)) {
         return false;
     }
     // Check if address has a valid postal code
     if ($this->postalCodes != '') {
         $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes);
         if (!in_array($objAddress->postal, $arrCodes)) {
             return false;
         }
     }
     $arrTypes = deserialize($this->product_types);
     if (is_array($arrTypes) && !empty($arrTypes)) {
         $arrItems = Isotope::getCart()->getItems();
         foreach ($arrItems as $objItem) {
             if (!$objItem->hasProduct() || !in_array($objItem->getProduct()->type, $arrTypes)) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function matchItem(ItemInterface $item)
 {
     if ($item->getType() != 'page') {
         return true;
     }
     if (!FE_USER_LOGGED_IN) {
         return false;
     }
     $pageGroups = deserialize($item->getExtra('groups'), true);
     if (empty($pageGroups)) {
         return true;
     }
     $memberGroups = \FrontendUser::getInstance()->groups;
     $groups = array_intersect($memberGroups, $pageGroups);
     return (bool) count($groups);
 }
Ejemplo n.º 17
0
 /**
  * This Hook provides case-insensitive contao-login by email usernames
  *
  * RFC 5321, section-2.3.11 says that email addresses should be treated as case-insensitive
  *
  * @param $strUser
  * @param $strPassword
  * @param $strTable
  *
  * @return bool
  */
 public function importUserHook($strUser, $strPassword, $strTable)
 {
     if (!\Validator::isEmail($strUser)) {
         return false;
     }
     switch ($strTable) {
         case 'tl_member':
             $objUser = \FrontendUser::getInstance();
             if ($objUser->findBy('LOWER(username)', strtolower($strUser)) !== false) {
                 // set post user name to the users username
                 \Input::setPost('username', $objUser->username);
                 return true;
             }
             break;
     }
     return false;
 }
Ejemplo n.º 18
0
 /**
  * @return string|void
  */
 public function generate()
 {
     define('MOD_MEMBER_RATING', 'true');
     require_once TL_ROOT . '/system/modules/member_rating/helper/functions.php';
     // Set the loggedInUser var
     if (FE_USER_LOGGED_IN) {
         $this->User = \FrontendUser::getInstance();
         $this->loggedInUser = $this->User;
     }
     // Overwrite imageDir if a custom directory was selected
     $this->setImageDir();
     // Load DCA
     $this->loadDataContainer('tl_comments');
     $this->loadDataContainer('tl_member');
     $this->loadLanguageFile('tl_comments');
     $this->loadLanguageFile('tl_member');
     return parent::generate();
 }
Ejemplo n.º 19
0
 public static function hasAccessToSearchResult(array $arrResult)
 {
     if (\Config::get('indexProtected') && !BE_USER_LOGGED_IN) {
         if (!$arrResult['protected']) {
             return true;
         }
         $objUser = \FrontendUser::getInstance();
         if (!FE_USER_LOGGED_IN) {
             return false;
         } else {
             $groups = deserialize($arrResult['groups']);
             if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $objUser->groups))) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 20
0
 /**
  * Generate the module
  * @return void
  */
 protected function compile()
 {
     $arrOrders = array();
     $objOrders = Order::findBy(array('order_status>0', 'member=?', 'config_id IN (?)'), array(\FrontendUser::getInstance()->id, implode("','", $this->iso_config_ids)), array('order' => 'locked DESC'));
     // No orders found, just display an "empty" message
     if (null === $objOrders) {
         $this->Template = new \Isotope\Template('mod_message');
         $this->Template->type = 'empty';
         $this->Template->message = $GLOBALS['TL_LANG']['ERR']['emptyOrderHistory'];
         return;
     }
     while ($objOrders->next()) {
         Isotope::setConfig($objOrders->current()->getRelated('config_id'));
         $arrOrders[] = array('collection' => $objOrders->current(), 'raw' => $objOrders->current()->row(), 'date' => Format::date($objOrders->current()->locked), 'time' => Format::time($objOrders->current()->locked), 'datime' => Format::datim($objOrders->current()->locked), 'grandTotal' => Isotope::formatPriceWithCurrency($objOrders->current()->getTotal()), 'status' => $objOrders->current()->getStatusLabel(), 'link' => $this->jumpTo ? \Haste\Util\Url::addQueryString('uid=' . $objOrders->current()->uniqid, $this->jumpTo) : '', 'class' => $objOrders->current()->getStatusAlias());
     }
     RowClass::withKey('class')->addFirstLast()->addEvenOdd()->applyTo($arrOrders);
     $this->Template->orders = $arrOrders;
 }
 public function hasAccess()
 {
     if (\Config::get('indexProtected') && !BE_USER_LOGGED_IN) {
         if (!$this->protected) {
             return true;
         }
         $objUser = \FrontendUser::getInstance();
         if (!FE_USER_LOGGED_IN) {
             return false;
         } else {
             $groups = deserialize($this->groups);
             if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $objUser->groups))) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 22
0
 /**
  * Authenticates username and password
  * @return boolean CUserIdentity::ERROR_NONE if successful authentication
  */
 public function authenticate()
 {
     $attribute = strpos($this->username, '@') ? 'email' : 'username';
     $user = FrontendUser::model()->find(array('condition' => $attribute . '=:loginname', 'params' => array(':loginname' => $this->username)));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$user->verifyPassword($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $user->regenerateValidationKey();
             $this->_id = $user->id;
             $this->username = $user->username;
             $this->setState('vkey', $user->validation_key);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
 /**
  * Module does not output anything...
  * Redirect if the user is logged in
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### LANGUAGE REDIRECT ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     // If user is logged in, redirect him
     if (FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN) {
         // try to switch the language/page
         if (\FrontendUser::getInstance()->language != $GLOBALS['TL_LANGUAGE']) {
             global $objPage;
             $mainLanguageID = $objPage->languageMain != 0 ? $objPage->languageMain : $objPage->id;
             $objPages = \Database::getInstance()->prepare("SELECT * FROM tl_page WHERE languageMain=? OR id=? AND published=?")->execute($mainLanguageID, $mainLanguageID, 1);
             while ($objPages->next()) {
                 // redirect
                 if ($objPages->language == \FrontendUser::getInstance()->language) {
                     $strParam = '';
                     $strGet = '?';
                     foreach ($_GET as $key => $value) {
                         switch ($key) {
                             case 'page':
                             case 'keywords':
                                 $strGet .= $key . '=' . $value . '&';
                                 break;
                             default:
                                 $strParam .= '/' . $key . '/' . $value;
                         }
                     }
                     $this->redirect($this->generateFrontendUrl($objPages->row(), $strParam) . $strGet);
                 }
             }
         }
     }
     // if user is not logged in, we have the correct language, or no page exists, we do nothing
     // assume Contao has found the right language...
     return '';
 }
Ejemplo n.º 24
0
 /**
  * Initialize the service factory.
  *
  * @param \Pimple $container The container.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function init($container)
 {
     try {
         // preserve object initialisation order
         if (TL_MODE == 'FE') {
             \FrontendUser::getInstance();
         } else {
             \BackendUser::getInstance();
         }
         // initialize the entity manager and class loaders
         $container['doctrine.orm.entityManager'];
         $this->createRecipientSourceService();
         $this->createQueueService();
         $this->createTransportService();
     } catch (\Exception $e) {
         $message = 'Could not create avisota services: ' . $e->getMessage();
         if ($e instanceof \ReflectionException) {
             $message .= PHP_EOL . 'You may need to run the database update!';
         }
         log_message($message . PHP_EOL . $e->getTraceAsString());
     }
 }
Ejemplo n.º 25
0
 /**
  * Return true or false depending on availability of the payment method
  * @return bool
  * @todo must check availability for a specific product collection (and not hardcoded to the current cart)
  */
 public function isAvailable()
 {
     if (!$this->enabled && BE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->guests && FE_USER_LOGGED_IN === true || $this->protected && FE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->protected) {
         $arrGroups = deserialize($this->groups);
         if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, \FrontendUser::getInstance()->groups))) {
             return false;
         }
     }
     if ($this->minimum_total > 0 && $this->minimum_total > Isotope::getCart()->getSubtotal() || $this->maximum_total > 0 && $this->maximum_total < Isotope::getCart()->getSubtotal()) {
         return false;
     }
     $arrCountries = deserialize($this->countries);
     if (is_array($arrCountries) && !empty($arrCountries) && !in_array(Isotope::getCart()->getBillingAddress()->country, $arrCountries)) {
         return false;
     }
     $arrShippings = deserialize($this->shipping_modules);
     if (is_array($arrShippings) && !empty($arrShippings) && (!Isotope::getCart()->hasShipping() && !in_array(-1, $arrShippings) || Isotope::getCart()->hasShipping() && !in_array(Isotope::getCart()->getShippingMethod()->id, $arrShippings))) {
         return false;
     }
     $arrTypes = deserialize($this->product_types);
     if (is_array($arrTypes) && !empty($arrTypes)) {
         $arrItems = Isotope::getCart()->getItems();
         foreach ($arrItems as $objItem) {
             if (!$objItem->hasProduct() || !in_array($objItem->getProduct()->type, $arrTypes)) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 26
0
 /**
  * Retrieve the currently logged in frontend user.
  *
  * @return bool|User
  */
 private function getMember()
 {
     return TL_MODE == 'FE' && FE_USER_LOGGED_IN ? FrontendUser::getInstance() : false;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var Message|\Model\Collection $objMessages */
     /** @noinspection PhpUndefinedMethodInspection */
     $objMessages = Message::findBy(array('pid IN (' . implode(',', $this->nc_member_customizable_notifications) . ') AND member_customizable<>\'\''), array());
     $arrOptions = array();
     $arrSelected = array();
     while ($objMessages->next()) {
         if (MemberMessages::memberHasSelected(\FrontendUser::getInstance()->id, $objMessages->id)) {
             $arrSelected[$objMessages->pid][] = $objMessages->id;
         }
         // Fetch tokens for parsing the option labels
         $objNotification = $objMessages->getRelated('pid');
         $objGateway = $objMessages->getRelated('gateway');
         $arrTokens = array_merge(array_combine(array_map(function ($key) {
             return 'message_' . $key;
         }, array_keys($objMessages->row())), $objMessages->row()), array_combine(array_map(function ($key) {
             return 'notification_' . $key;
         }, array_keys($objNotification->row())), $objNotification->row()), array_combine(array_map(function ($key) {
             return 'gateway_' . $key;
         }, array_keys($objGateway->row())), $objGateway->row()));
         $arrOptions[$objMessages->pid][$objMessages->id] = \StringUtil::parseSimpleTokens($this->nc_member_customizable_label ?: '##message_title## (##gateway_title##)', $arrTokens);
     }
     $objForm = new Form('tl_select_notifications', 'POST', function ($objHaste) {
         /** @noinspection PhpUndefinedMethodInspection */
         return \Input::post('FORM_SUBMIT') === $objHaste->getFormId();
     });
     foreach ($arrOptions as $k => $options) {
         /** @noinspection PhpUndefinedMethodInspection */
         $objForm->addFormField('notification_' . $k, array('label' => Notification::findByPk($objMessages->pid)->title, 'inputType' => $this->nc_member_customizable_inputType, 'options' => $options, 'eval' => array('mandatory' => $this->nc_member_customizable_mandatory), 'value' => !empty($arrSelected[$k]) ? $arrSelected[$k] : array()));
         // Add a validator
         // We check whether it is possible to send the message to the recipient by means of the gateway
         // E.g. a sms message requires a phone number set by the member which is not default
         $objForm->addValidator('notification_' . $k, function ($varValue, $objWidget, $objForm) use($k, $arrOptions) {
             if (empty($varValue)) {
                 return $varValue;
             }
             foreach ($varValue as $msg) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 /** @var Message|\Model $objMessage */
                 $objMessage = Message::findByPk($msg);
                 /** @noinspection PhpUndefinedMethodInspection */
                 /** @var GatewayInterface|MessageDraftCheckSendInterface $objGateway */
                 $objGateway = $objMessage->getRelated('gateway')->getGateway();
                 if (!$objGateway instanceof MessageDraftCheckSendInterface) {
                     continue;
                 }
                 // Throw the error message as exception if the method has not yet
                 if (!$objGateway->canSendDraft($objMessage)) {
                     throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['messageNotSelectable'], $arrOptions[$k][$msg]));
                 }
             }
             return $varValue;
         });
     }
     $objForm->addSubmitFormField('submit', $GLOBALS['TL_LANG']['MSC']['saveSettings']);
     // Process form submit
     if ($objForm->validate()) {
         $arrData = $objForm->fetchAll();
         foreach ($arrData as $field => $notification) {
             if (strpos($field, 'notification_') !== 0) {
                 continue;
             }
             list(, $notificationId) = trimsplit('_', $field);
             // Delete
             foreach (array_diff((array) $arrSelected[$notificationId], (array) $notification) as $msg) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 MemberMessages::findByMemberAndMessage(\FrontendUser::getInstance()->id, $msg)->delete();
             }
             // Create
             foreach (array_diff((array) $notification, (array) $arrSelected[$notificationId]) as $msg) {
                 /** @var MemberMessages|\Model $objMemberMessage */
                 $objMemberMessage = new MemberMessages();
                 $objMemberMessage->member_id = \FrontendUser::getInstance()->id;
                 $objMemberMessage->message_id = $msg;
                 $objMemberMessage->save();
             }
         }
     }
     $this->Template->form = $objForm->generate();
 }
Ejemplo n.º 28
0
 /**
  * Delete the given address and make sure it belongs to the current frontend user
  * @param integer
  * @return void
  */
 protected function delete($intAddressId)
 {
     if (($objAddress = Address::findOneForMember($intAddressId, \FrontendUser::getInstance()->id)) !== null) {
         $objAddress->delete();
     }
     global $objPage;
     \Controller::redirect(\Controller::generateFrontendUrl($objPage->row()));
 }
Ejemplo n.º 29
0
 /**
  * Return the current object instance (Singleton)
  * @return object
  */
 public static function getInstance()
 {
     if (!is_object(self::$objInstance)) {
         self::$objInstance = new FrontendUser();
     }
     return self::$objInstance;
 }
 public function generate()
 {
     $this->intId = \FrontendUser::getInstance()->id;
     return parent::generate();
 }