/** * 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] . '"'; } } }
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!'); }
/** * 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); }
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; } } }
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']); } } } }
/** * 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; }
/** * @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); }
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; }
/** * 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; }
/** * 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; }
/** * {@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); }
/** * 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; }
/** * 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); }
/** * 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; }
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; }
/** * @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(); }
/** * 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; }
/** * 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&table=tl_module&act=edit&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 ''; }
/** * 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()); } }
/** * 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; }
/** * Return sorted and serialized list of active member groups for cache lookup * * @return string */ public static function getCacheableGroups() { static $groups = null; if (null === $groups) { $groups = ''; if (FE_USER_LOGGED_IN === true) { /** @var \FrontendUser|object $user */ $user = \FrontendUser::getInstance(); $arrGroups = $user->groups; if (!empty($arrGroups) && is_array($arrGroups)) { // Make sure groups array always looks the same to find it in the database $arrGroups = array_unique($arrGroups); sort($arrGroups, SORT_NUMERIC); $groups = serialize($arrGroups); } } } return $groups; }
/** * 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(); }
/** * Check whether an element is visible in the front end * * @param \Model|\ContentModel|\ModuleModel $objElement The element model * * @return boolean True if the element is visible */ public static function isVisibleElement(\Model $objElement) { // Only apply the restrictions in the front end if (TL_MODE != 'FE' || BE_USER_LOGGED_IN) { return true; } $blnReturn = true; // Protected element if ($objElement->protected) { if (!FE_USER_LOGGED_IN) { $blnReturn = false; } else { $groups = deserialize($objElement->groups); if (empty($groups) || !is_array($groups) || !count(array_intersect($groups, \FrontendUser::getInstance()->groups))) { $blnReturn = false; } } } elseif ($objElement->guests && FE_USER_LOGGED_IN) { $blnReturn = false; } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['isVisibleElement']) && is_array($GLOBALS['TL_HOOKS']['isVisibleElement'])) { foreach ($GLOBALS['TL_HOOKS']['isVisibleElement'] as $callback) { $blnReturn = static::importStatic($callback[0])->{$callback[1]}($objElement, $blnReturn); } } return $blnReturn; }
/** * Return all available variant IDs of this product * * @return int[]|false */ public function getVariantIds() { if (null === $this->arrVariantIds) { $this->arrVariantIds = array(); // Nothing to do if we have no variants if (!$this->hasVariants()) { return $this->arrVariantIds; } $time = time(); $blnHasProtected = false; $blnHasGroups = false; $strQuery = "SELECT id, protected, groups FROM tl_iso_product WHERE pid=" . $this->getProductId() . " AND language='' AND published='1' AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time})"; if (BE_USER_LOGGED_IN !== true) { $arrAttributes = $this->getVariantAttributes(); $blnHasProtected = in_array('protected', $arrAttributes); $blnHasGroups = in_array('groups', $arrAttributes); // Hide guests-only products when logged in if (FE_USER_LOGGED_IN === true && in_array('guests', $arrAttributes)) { $strQuery .= " AND (guests=''" . ($blnHasProtected ? " OR protected='1'" : '') . ")"; } elseif (FE_USER_LOGGED_IN !== true && $blnHasProtected) { $strQuery .= " AND protected=''"; } } /** @type object $objVariants */ $objVariants = \Database::getInstance()->query($strQuery); while ($objVariants->next()) { if ($blnHasProtected && $objVariants->protected) { $groups = $blnHasGroups ? deserialize($objVariants->groups) : ''; if (empty($groups) || !is_array($groups) || !count(array_intersect($groups, \FrontendUser::getInstance()->groups))) { continue; } } $this->arrVariantIds[] = $objVariants->id; } // Only show variants where a price is available if (!empty($this->arrVariantIds) && $this->hasVariantPrices()) { if ($this->hasAdvancedPrices()) { $objPrices = ProductPrice::findAdvancedByProductIdsAndCollection($this->arrVariantIds, Isotope::getCart()); } else { $objPrices = ProductPrice::findPrimaryByProductIds($this->arrVariantIds); } if (null === $objPrices) { $this->arrVariantIds = array(); } else { $this->arrVariantIds = $objPrices->fetchEach('pid'); } } } return $this->arrVariantIds; }
public function generate() { $this->intId = \FrontendUser::getInstance()->id; return parent::generate(); }
/** * Retrieve the currently logged in frontend user. * * @return bool|User */ private function getMember() { return TL_MODE == 'FE' && FE_USER_LOGGED_IN ? FrontendUser::getInstance() : false; }
/** * 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())); }