/**
  * Generate array representation for download
  *
  * @param bool $blnOrderPaid
  *
  * @return array
  */
 public function getForTemplate($blnOrderPaid = false)
 {
     global $objPage;
     $objDownload = $this->getRelated('download_id');
     if (null === $objDownload) {
         return array();
     }
     $arrDownloads = array();
     $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
     foreach ($objDownload->getFiles() as $objFileModel) {
         $objFile = new \File($objFileModel->path, true);
         if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
             continue;
         }
         // Send file to the browser
         if ($blnOrderPaid && $this->canDownload() && \Input::get('download') == $objDownload->id && \Input::get('file') == $objFileModel->path) {
             $this->download($objFileModel->path);
         }
         $arrMeta = \Frontend::getMetaData($objFileModel->meta, $objPage->language);
         // Use the file name as title if none is given
         if ($arrMeta['title'] == '') {
             $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
         }
         $strHref = '';
         if (TL_MODE == 'FE') {
             $strHref = \Haste\Util\Url::addQueryString('download=' . $objDownload->id . '&file=' . $objFileModel->path);
         }
         // Add the image
         $arrDownloads[] = array('id' => $this->id, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname, 'remaining' => $objDownload->downloads_allowed > 0 ? sprintf($GLOBALS['TL_LANG']['MSC']['downloadsRemaining'], intval($this->downloads_remaining)) : '', 'downloadable' => $blnOrderPaid && $this->canDownload());
     }
     return $arrDownloads;
 }
Esempio n. 2
0
 /**
  * Callback for add_to_cart button
  * @param object
  * @param array
  */
 public function addToCart($objProduct, array $arrConfig = array())
 {
     $objModule = $arrConfig['module'];
     $intQuantity = $objModule->iso_use_quantity && intval(\Input::post('quantity_requested')) > 0 ? intval(\Input::post('quantity_requested')) : 1;
     if (Isotope::getCart()->addProduct($objProduct, $intQuantity, $arrConfig) !== false) {
         $_SESSION['ISO_CONFIRM'][] = $GLOBALS['TL_LANG']['MSC']['addedToCart'];
         if (!$objModule->iso_addProductJumpTo) {
             $this->reload();
         }
         \Controller::redirect(\Haste\Util\Url::addQueryString('continue=' . base64_encode(\Environment::get('request')), $objModule->iso_addProductJumpTo));
     }
 }
Esempio n. 3
0
 public static function generateUrl($strGroup, $strAction = null, array $arrAttributes = array(), $blnKeepParams = true, $strUrl = null)
 {
     global $objPage;
     if ($strUrl === null) {
         $strUrl = $blnKeepParams ? null : \Controller::generateFrontendUrl($objPage->row(), null, null, true);
     }
     $strUrl = Url::addQueryString(Ajax::AJAX_ATTR_SCOPE . '=' . Ajax::AJAX_SCOPE_DEFAULT, $strUrl);
     $strUrl = Url::addQueryString(Ajax::AJAX_ATTR_GROUP . '=' . $strGroup, $strUrl);
     if ($strAction !== null) {
         $strUrl = Url::addQueryString(Ajax::AJAX_ATTR_ACT . '=' . $strAction, $strUrl);
     }
     foreach ($arrAttributes as $key => $attribute) {
         $strUrl = Url::addQueryString($key . '=' . $attribute, $strUrl);
     }
     return $strUrl;
 }
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  */
 protected function doSwitchView($id)
 {
     list($table, $id) = explode('.', $id);
     $url = Url::removeQueryString(['switchLanguage']);
     switch ($table) {
         case 'tl_article':
             $url = Url::addQueryString('id=' . $id, $url);
             break;
         case 'tl_page':
             Session::getInstance()->set('tl_page_node', (int) $id);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Table "%s" is not supported', $table));
     }
     Controller::redirect($url);
 }
Esempio n. 5
0
 /**
  * Callback for add_to_cart button
  *
  * @param IsotopeProduct $objProduct
  * @param array          $arrConfig
  */
 public function addToCart(IsotopeProduct $objProduct, array $arrConfig = array())
 {
     $objModule = $arrConfig['module'];
     $intQuantity = $objModule->iso_use_quantity && intval(\Input::post('quantity_requested')) > 0 ? intval(\Input::post('quantity_requested')) : 1;
     // Do not add parent of variant product to the cart
     if ($objProduct->hasVariants() && !$objProduct->isVariant()) {
         return;
     }
     if (Isotope::getCart()->addProduct($objProduct, $intQuantity, $arrConfig) !== false) {
         Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['addedToCart']);
         if (!$objModule->iso_addProductJumpTo) {
             $this->reload();
         }
         \Controller::redirect(\Haste\Util\Url::addQueryString('continue=' . base64_encode(\Environment::get('request')), $objModule->iso_addProductJumpTo));
     }
 }
 public static function generateUnlockForm($strTable, $objEntity, $objLock, $objModule, $arrTokens = array())
 {
     $objTemplate = new \FrontendTemplate('entity_lock_unlock_form');
     $objTemplate->action = Url::addQueryString('act=unlock', \Environment::get('uri'));
     $objTemplate->formId = 'entity_lock_unlock_' . $objModule->id;
     $objTemplate->lock = $objLock->id;
     // delete if preconditions are given - allow only for the current lock
     $blnIsSubmitted = \Input::post('FORM_SUBMIT') == $objTemplate->formId;
     if ($blnIsSubmitted && \Input::get('act') == EntityLock::ACT_UNLOCK && $objLock->id == \Input::post('lock')) {
         $objFormerEditor = EntityLockModel::getEditor($objLock->id);
         if ($objLock->delete() && $objModule->lockDeletionNotification) {
             static::sendLockDeletionNotification($objModule->lockDeletionNotification, $strTable, $objEntity, $objFormerEditor, $arrTokens);
         }
         \Controller::redirect(Url::removeQueryString(array('act')), $objTemplate->action);
     }
     return $objTemplate->parse();
 }
 /**
  * Return the "toggle visibility" button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
 {
     if (strlen(Input::get('tid'))) {
         $this->toggleVisibility(Input::get('tid'), Input::get('state') == 1, @func_get_arg(12) ?: null);
         $this->redirect($this->getReferer());
     }
     // Check permissions AFTER checking the tid, so hacking attempts are logged
     if (!$this->User->hasAccess(\Config::get('fielpalette_table') . '::published', 'alexf')) {
         return '';
     }
     $href = \Haste\Util\Url::addQueryString('tid=' . $row['id'], $href);
     $href = \Haste\Util\Url::addQueryString('state=' . ($row['published'] ? '' : 1), $href);
     if (!$row['published']) {
         $icon = 'invisible.gif';
     }
     return '<a href="' . $href . '" title="' . specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"') . '</a> ';
 }
Esempio n. 8
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;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->blnUpdateCache = \Input::post('FORM_SUBMIT') == 'iso_filter_' . $this->id ? true : false;
     $this->generateFilters();
     $this->generateSorting();
     $this->generateLimit();
     if (!$this->blnUpdateCache) {
         // Search does not affect request cache
         $this->generateSearch();
         $arrParams = array_filter(array_keys($_GET), function ($key) {
             return strpos($key, 'page_iso') === 0;
         });
         $this->Template->id = $this->id;
         $this->Template->formId = 'iso_filter_' . $this->id;
         $this->Template->action = ampersand(Url::removeQueryString($arrParams));
         $this->Template->actionClear = ampersand(strtok(\Environment::get('request'), '?')) . "?keywords=" . \Input::get('keywords');
         $this->Template->clearLabel = $GLOBALS['TL_LANG']['MSC']['clearFiltersLabel'];
         $this->Template->slabel = $GLOBALS['TL_LANG']['MSC']['submitLabel'];
     }
 }
Esempio n. 10
0
 /**
  * Generate frontend URL for current page including the given checkout step
  *
  * @param string                   $strStep
  * @param IsotopeProductCollection $objCollection
  * @param \PageModel               $objTarget
  *
  * @return string
  */
 public static function generateUrlForStep($strStep, IsotopeProductCollection $objCollection = null, \PageModel $objTarget = null)
 {
     if (null === $objTarget) {
         global $objPage;
         $objTarget = $objPage;
     }
     if (!$GLOBALS['TL_CONFIG']['useAutoItem'] || !in_array('step', $GLOBALS['TL_AUTO_ITEM'])) {
         $strStep = 'step/' . $strStep;
     }
     $strUrl = \Controller::generateFrontendUrl($objTarget->row(), '/' . $strStep, $objTarget->language);
     if (null !== $objCollection) {
         $strUrl = \Haste\Util\Url::addQueryString('uid=' . $objCollection->uniqid, $strUrl);
     }
     return $strUrl;
 }
Esempio n. 11
0
 /**
  * Generate url
  *
  * @param \PageModel $objJumpTo A PageModel instance
  *
  * @return string
  */
 public function generateUrl(\PageModel $objJumpTo = null)
 {
     if (null === $objJumpTo) {
         global $objPage;
         global $objIsotopeListPage;
         $objJumpTo = $objIsotopeListPage ?: $objPage;
         if (null === $objJumpTo) {
             return '';
         }
     }
     $strUrl = '/' . $this->arrData['alias'] ?: $this->getProductId();
     if (!$GLOBALS['TL_CONFIG']['useAutoItem'] || !in_array('product', $GLOBALS['TL_AUTO_ITEM'])) {
         $strUrl = '/product' . $strUrl;
     }
     return \Haste\Util\Url::addQueryString(http_build_query($this->getOptions()), \Controller::generateFrontendUrl($objJumpTo->row(), $strUrl, $objJumpTo->language));
 }
Esempio n. 12
0
 /**
  * Generate module
  */
 protected function compile()
 {
     if (Isotope::getCart()->isEmpty()) {
         $this->Template->empty = true;
         $this->Template->type = 'empty';
         $this->Template->message = $this->iso_emptyMessage ? $this->iso_noProducts : $GLOBALS['TL_LANG']['MSC']['noItemsInCart'];
         return;
     }
     // Remove from cart
     if (\Input::get('remove') > 0 && Isotope::getCart()->deleteItemById((int) \Input::get('remove'))) {
         \Controller::redirect(preg_replace('/([?&])remove=[^&]*(&|$)/', '$1', \Environment::get('request')));
     }
     $objTemplate = new \Isotope\Template($this->iso_collectionTpl);
     Isotope::getCart()->addToTemplate($objTemplate, array('gallery' => $this->iso_gallery, 'sorting' => Isotope::getCart()->getItemsSortingCallable($this->iso_orderCollectionBy)));
     $blnReload = false;
     $arrQuantity = \Input::post('quantity');
     $arrItems = $objTemplate->items;
     foreach ($arrItems as $k => $arrItem) {
         // Update cart data if form has been submitted
         if (\Input::post('FORM_SUBMIT') == $this->strFormId && is_array($arrQuantity) && isset($arrQuantity[$arrItem['id']])) {
             $blnReload = true;
             Isotope::getCart()->updateItemById($arrItem['id'], array('quantity' => $arrQuantity[$arrItem['id']]));
             continue;
             // no need to generate $arrProductData, we reload anyway
         }
         $arrItem['remove_href'] = \Haste\Util\Url::addQueryString('remove=' . $arrItem['id']);
         $arrItem['remove_title'] = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['removeProductLinkTitle'], $arrItem['name']));
         $arrItem['remove_link'] = $GLOBALS['TL_LANG']['MSC']['removeProductLinkText'];
         $arrItems[$k] = $arrItem;
     }
     $arrButtons = $this->generateButtons();
     // Reload the page if no button has handled it
     if ($blnReload) {
         // Unset payment and shipping method because they could get invalid due to the change
         // @todo change this to check availability, but that's an API/BC break
         if (($objShipping = Isotope::getCart()->getShippingMethod()) !== null && !$objShipping->isAvailable()) {
             Isotope::getCart()->setShippingMethod(null);
         }
         if (($objPayment = Isotope::getCart()->getPaymentMethod()) !== null && !$objPayment->isAvailable()) {
             Isotope::getCart()->setPaymentMethod(null);
         }
         \Controller::reload();
     }
     $objTemplate->items = $arrItems;
     $objTemplate->isEditable = true;
     $objTemplate->linkProducts = true;
     $objTemplate->formId = $this->strFormId;
     $objTemplate->formSubmit = $this->strFormId;
     $objTemplate->action = \Environment::get('request');
     $objTemplate->buttons = $arrButtons;
     $objTemplate->custom = '';
     // HOOK: order status has been updated
     if (isset($GLOBALS['ISO_HOOKS']['compileCart']) && is_array($GLOBALS['ISO_HOOKS']['compileCart'])) {
         $strCustom = '';
         foreach ($GLOBALS['ISO_HOOKS']['compileCart'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $strCustom .= $objCallback->{$callback}[1]($this);
         }
         $objTemplate->custom = $strCustom;
     }
     $this->Template->empty = false;
     $this->Template->collection = Isotope::getCart();
     $this->Template->products = $objTemplate->parse();
 }
Esempio n. 13
0
 /**
  * @dataProvider removeQueryStringProvider
  */
 public function testRemoveQueryString($request, $paramsToRemove, $expectedResult)
 {
     $this->assertSame($expectedResult, Url::removeQueryString($paramsToRemove, $request));
 }
Esempio n. 14
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->blnUpdateCache = \Input::post('FORM_SUBMIT') == 'iso_filter_' . $this->id;
     $this->generateFilters();
     $this->generateSorting();
     $this->generateLimit();
     // If we update the cache and reload the page, we don't need to build the template
     if ($this->blnUpdateCache) {
         return;
     }
     // Search does not affect request cache
     $this->generateSearch();
     $arrParams = array_filter(array_keys($_GET), function ($key) {
         return strpos($key, 'page_iso') === 0;
     });
     $this->Template->id = $this->id;
     $this->Template->formId = 'iso_filter_' . $this->id;
     $this->Template->action = ampersand(Url::removeQueryString($arrParams));
     $this->Template->actionClear = ampersand(strtok(\Environment::get('request'), '?'));
     $this->Template->clearLabel = $GLOBALS['TL_LANG']['MSC']['clearFiltersLabel'];
     $this->Template->slabel = $GLOBALS['TL_LANG']['MSC']['submitLabel'];
 }
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  */
 protected function doSwitchView($id)
 {
     $url = Url::removeQueryString(['switchLanguage']);
     $url = Url::addQueryString('id=' . $id, $url);
     Controller::redirect($url);
 }
 /**
  * Generates an url for the step.
  *
  * @param int $step
  *
  * @return mixed
  */
 public function getUrlForStep($step)
 {
     if (0 === $step) {
         $url = \Haste\Util\Url::removeQueryString([$this->getGetParam()]);
     } else {
         $url = \Haste\Util\Url::addQueryString($this->getGetParam() . '=' . $step);
     }
     return $url;
 }
 /**
  * @param string $action
  * @param string $attribute
  * @param string $value
  */
 private function saveFilter($action, $attribute, $value)
 {
     if ($action == 'add') {
         Isotope::getRequestCache()->setFiltersForModule($this->addFilter($this->activeFilters, $attribute, $value), $this->id);
     } else {
         Isotope::getRequestCache()->removeFilterForModule($this->generateFilterKey($attribute, $value), $this->id);
     }
     $objCache = Isotope::getRequestCache()->saveNewConfiguration();
     // Include \Environment::base or the URL would not work on the index page
     \Controller::redirect(\Environment::get('base') . Url::addQueryString('isorc=' . $objCache->id, Url::removeQueryString(array('cumulativefilter'), $this->jumpTo ?: null)));
 }
 /**
  * @inheritdoc
  */
 protected function doSwitchView($id)
 {
     Session::getInstance()->set('tl_page_node', (int) $id);
     Controller::redirect(Url::removeQueryString(['switchLanguage']));
 }
Esempio n. 19
0
 /**
  * Generates the filter
  */
 protected function generateFilter()
 {
     $blnShowClear = false;
     $arrFilters = array();
     foreach ($this->iso_filterFields as $strField) {
         $blnTrail = false;
         $arrItems = array();
         $arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField], $strField);
         // Use the default routine to initialize options data
         foreach ($arrWidget['options'] as $option) {
             $varValue = $option['value'];
             // skip zero values (includeBlankOption)
             // @deprecated drop "-" when we only have the database table as options source
             if ($varValue === '' || $varValue === '-') {
                 continue;
             }
             $strFilterKey = $strField . '=' . $varValue;
             $blnActive = Isotope::getRequestCache()->getFilterForModule($strFilterKey, $this->id) !== null;
             $blnTrail = $blnActive ? true : $blnTrail;
             $arrItems[] = array('href' => \Haste\Util\Url::addQueryString('cumulativefilter=' . base64_encode($this->id . ';' . ($blnActive ? 'del' : 'add') . ';' . $strField . ';' . $varValue)), 'class' => $blnActive ? 'active' : '', 'title' => specialchars($option['label']), 'link' => $option['label']);
         }
         if (!empty($arrItems) || $this->iso_iso_filterHideSingle && count($arrItems) < 2) {
             $objClass = RowClass::withKey('class')->addFirstLast();
             if ($blnTrail) {
                 $objClass->addCustom('sibling');
             }
             $objClass->applyTo($arrItems);
             $objTemplate = new \Isotope\Template($this->navigationTpl);
             $objTemplate->level = 'level_2';
             $objTemplate->items = $arrItems;
             $arrFilters[$strField] = array('label' => $arrWidget['label'], 'subitems' => $objTemplate->parse(), 'isActive' => $blnTrail);
             $blnShowClear = $blnTrail ? true : $blnShowClear;
         }
     }
     $this->Template->filters = $arrFilters;
     $this->Template->showClear = $blnShowClear;
 }
 protected function generateHref()
 {
     $strUrl = $this->base;
     $arrParameters = $this->prepareParameter($this->act);
     foreach ($arrParameters as $key => $value) {
         $strUrl = \Haste\Util\Url::addQueryString($key . '=' . $value, $strUrl);
     }
     if (in_array('popup', $arrParameters)) {
         $strUrl = \Haste\Util\Url::addQueryString('popup=1', $strUrl);
         $this->arrOptions['attributes']['onclick'] = 'onclick="FieldPaletteBackend.openModalIframe({\'action\':\'' . FieldPalette::$strFieldpaletteRefreshAction . '\',\'syncId\':\'' . $this->syncId . '\',\'width\':768,\'title\':\'' . specialchars(sprintf($this->modalTitle, $this->id)) . '\',\'url\':this.href});return false;"';
     }
     $strUrl = \Haste\Util\Url::addQueryString('rt=' . \RequestToken::get(), $strUrl);
     // TODO: DC_TABLE : 2097 - catch POST and Cookie from saveNClose and do not redirect and just close modal
     $strUrl = \Haste\Util\Url::addQueryString('nb=1', $strUrl);
     // required by DC_TABLE::getNewPosition() within nested fieldpalettes
     $strUrl = \Haste\Util\Url::addQueryString('mode=2', $strUrl);
     return $strUrl;
 }