/** * Load a module if we need to * @return string */ public function run() { $varResponse = false; //Legacy Frontend Module Requests if (AjaxInput::get('action') == 'fmd' && AjaxInput::get('id') > 0) { //Restore Input vars AjaxInput::restore(); $strBuffer = static::getFrontendModuleAjax(AjaxInput::get('id')); $objResponse = new HtmlResponse($strBuffer); $objResponse->send(); } //Legacy Content Element Requests if (AjaxInput::get('action') == 'cte' && AjaxInput::get('id') > 0) { //Restore Input vars AjaxInput::restore(); $strBuffer = static::getContentElementAjax(AjaxInput::get('id')); $objResponse = new HtmlResponse($strBuffer); $objResponse->send(); } //Legacy Form Field Requests if (AjaxInput::get('action') == 'ffl' && AjaxInput::get('id') > 0) { //Restore Input vars AjaxInput::restore(); $strBuffer = static::getFormFieldAjax(AjaxInput::get('id')); $objResponse = new HtmlResponse($strBuffer); $objResponse->send(); } }
/** * Get a request token * @return void */ public function run() { if (AjaxInput::post('action') == 'getRequestToken') { $objResponse = new HtmlResponse(\RequestToken::get()); $objResponse->send(); } }
protected function compile() { $arrProducts = $this->findProducts(); // No products found if (!is_array($arrProducts) || empty($arrProducts)) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; $this->Template->empty = true; $this->Template->type = 'empty'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['noProducts']; $this->Template->products = array(); return; } $arrBuffer = array(); foreach ($arrProducts as $objProduct) { $arrConfig = array('module' => $this, 'template' => $this->iso_list_layout ?: $objProduct->getRelated('type')->list_template, 'gallery' => $this->iso_gallery ?: $objProduct->getRelated('type')->list_gallery, 'buttons' => deserialize($this->iso_buttons, true), 'useQuantity' => $this->iso_use_quantity, 'jumpTo' => $this->findJumpToPage($objProduct)); if (\Environment::get('isAjaxRequest') && \Input::post('AJAX_MODULE') == $this->id && \Input::post('AJAX_PRODUCT') == $objProduct->getProductId()) { $objResponse = new HtmlResponse($objProduct->generate($arrConfig)); $objResponse->send(); } $arrCSS = deserialize($objProduct->cssID, true); $arrBuffer[] = array('cssID' => $arrCSS[0] != '' ? ' id="' . $arrCSS[0] . '"' : '', 'class' => trim('product ' . ($objProduct->isNew() ? 'new ' : '') . $arrCSS[1]), 'html' => $objProduct->generate($arrConfig), 'product' => $objProduct); } // HOOK: to add any product field or attribute to mod_iso_productlist template if (isset($GLOBALS['ISO_HOOKS']['generateProductList']) && is_array($GLOBALS['ISO_HOOKS']['generateProductList'])) { foreach ($GLOBALS['ISO_HOOKS']['generateProductList'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrBuffer = $objCallback->{$callback}[1]($arrBuffer, $arrProducts, $this->Template, $this); } } RowClass::withKey('class')->addCount('product_')->addEvenOdd('product_')->addFirstLast('product_')->addGridRows($this->iso_cols)->addGridCols($this->iso_cols)->applyTo($arrBuffer); $this->Template->products = $arrBuffer; }
/** * Log a message in Contao * @return void */ public function run() { if (AjaxInput::get('action') == 'logMessage' && AjaxInput::get('logDetails')) { \System::log(AjaxInput::get('logDetails'), AjaxInput::get('logMethod') ?: __METHOD__, AjaxInput::get('logCategory') ?: TL_GENERAL); $objResponse = new HtmlResponse(1); $objResponse->send(); } }
public static function reload() { static::$objStatic->Template = new \FrontendTemplate('ajaxform_confirm'); static::$objStatic->Template->message = static::$objStatic->objParent->text; if (\Environment::get('isAjaxRequest')) { $objResponse = new HtmlResponse(static::$objStatic->objParent->text ? static::$objStatic->Template->parse() : 'true'); $objResponse->send(); } if (static::$objStatic->objParent->text) { return; } }
/** * Generate module * @return void */ protected function compile() { global $objPage; global $objIsotopeListPage; $objProduct = Product::findAvailableByIdOrAlias(\Haste\Input\Input::getAutoItem('product')); if (null === $objProduct) { $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); exit; } $arrConfig = array('module' => $this, 'template' => $this->iso_reader_layout ?: $objProduct->getRelated('type')->reader_template, 'gallery' => $this->iso_gallery ?: $objProduct->getRelated('type')->reader_gallery, 'buttons' => deserialize($this->iso_buttons, true), 'useQuantity' => $this->iso_use_quantity, 'jumpTo' => $objIsotopeListPage ?: $objPage); if (\Environment::get('isAjaxRequest') && \Input::post('AJAX_MODULE') == $this->id && \Input::post('AJAX_PRODUCT') == $objProduct->getProductId()) { $objResponse = new HtmlResponse($objProduct->generate($arrConfig)); $objResponse->send(); } $arrCSS = deserialize($objProduct->cssID, true); $this->Template->product = $objProduct->generate($arrConfig); $this->Template->product_id = $arrCSS[0] != '' ? ' id="' . $arrCSS[0] . '"' : ''; $this->Template->product_class = trim('product ' . ($objProduct->isNew() ? 'new ' : '') . $arrCSS[1]); $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $this->addMetaTags($objProduct); $this->addCanonicalProductUrls($objProduct); }
/** * Compile product list. * * This function is specially designed so you can keep it in your child classes and only override findProducts(). * You will automatically gain product caching (see class property), grid classes, pagination and more. */ protected function compile() { // return message if no filter is set if ($this->iso_emptyFilter && !\Input::get('isorc') && !\Input::get('keywords')) { $this->Template->message = $this->replaceInsertTags($this->iso_noFilter); $this->Template->type = 'noFilter'; $this->Template->products = array(); return; } global $objPage; $intPage = $this->iso_category_scope == 'article' ? $GLOBALS['ISO_CONFIG']['current_article']['pid'] : $objPage->id; $arrProducts = null; $arrCacheIds = null; // Try to load the products from cache if ($this->blnCacheProducts && ($objCache = ProductCache::findForPageAndModule($intPage, $this->id)) !== null) { $arrCacheIds = $objCache->getProductIds(); // Use the cache if keywords match. Otherwise we will use the product IDs as a "limit" for findProducts() if ($objCache->keywords == \Input::get('keywords')) { $arrCacheIds = $this->generatePagination($arrCacheIds); $objProducts = Product::findAvailableByIds($arrCacheIds, array('order' => \Database::getInstance()->findInSet(Product::getTable() . '.id', $arrCacheIds))); $arrProducts = null === $objProducts ? array() : $objProducts->getModels(); // Cache is wrong, drop everything and run findProducts() if (count($arrProducts) != count($arrCacheIds)) { $arrCacheIds = null; $arrProducts = null; } } } if (!is_array($arrProducts)) { // Display "loading products" message and add cache flag if ($this->blnCacheProducts) { $blnCacheMessage = (bool) $this->iso_productcache[$intPage][(int) \Input::get('isorc')]; if ($blnCacheMessage && !\Input::get('buildCache')) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; $this->Template = new \Isotope\Template('mod_iso_productlist_caching'); $this->Template->message = $GLOBALS['TL_LANG']['MSC']['productcacheLoading']; return; } // Start measuring how long it takes to load the products $start = microtime(true); // Load products $arrProducts = $this->findProducts($arrCacheIds); // Decide if we should show the "caching products" message the next time $end = microtime(true) - $start; $this->blnCacheProducts = $end > 1 ? true : false; $arrCacheMessage = $this->iso_productcache; if ($blnCacheMessage != $this->blnCacheProducts) { $arrCacheMessage[$intPage][(int) \Input::get('isorc')] = $this->blnCacheProducts; \Database::getInstance()->prepare("UPDATE tl_module SET iso_productcache=? WHERE id=?")->execute(serialize($arrCacheMessage), $this->id); } // Do not write cache if table is locked. That's the case if another process is already writing cache if (ProductCache::isWritable()) { \Database::getInstance()->lockTables(array(ProductCache::getTable() => 'WRITE', 'tl_iso_product' => 'READ')); $arrIds = array(); foreach ($arrProducts as $objProduct) { $arrIds[] = $objProduct->id; } // Delete existing cache if necessary ProductCache::deleteForPageAndModuleOrExpired($intPage, $this->id); $objCache = ProductCache::createForPageAndModule($intPage, $this->id); $objCache->expires = $this->getProductCacheExpiration(); $objCache->setProductIds($arrIds); $objCache->save(); \Database::getInstance()->unlockTables(); } } else { $arrProducts = $this->findProducts(); } if (!empty($arrProducts)) { $arrProducts = $this->generatePagination($arrProducts); } } // No products found if (!is_array($arrProducts) || empty($arrProducts)) { $this->compileEmptyMessage(); return; } $arrBuffer = array(); $arrDefaultOptions = $this->getDefaultProductOptions(); /** @var \Isotope\Model\Product\Standard $objProduct */ foreach ($arrProducts as $objProduct) { $arrConfig = array('module' => $this, 'template' => $this->iso_list_layout ?: $objProduct->getRelated('type')->list_template, 'gallery' => $this->iso_gallery ?: $objProduct->getRelated('type')->list_gallery, 'buttons' => deserialize($this->iso_buttons, true), 'useQuantity' => $this->iso_use_quantity, 'jumpTo' => $this->findJumpToPage($objProduct)); if (\Environment::get('isAjaxRequest') && \Input::post('AJAX_MODULE') == $this->id && \Input::post('AJAX_PRODUCT') == $objProduct->getProductId()) { $objResponse = new HtmlResponse($objProduct->generate($arrConfig)); $objResponse->send(); } $objProduct->mergeRow($arrDefaultOptions); // Must be done after setting options to generate the variant config into the URL if ($this->iso_jump_first && \Haste\Input\Input::getAutoItem('product', false, true) == '') { \Controller::redirect($objProduct->generateUrl($arrConfig['jumpTo'])); } $arrCSS = deserialize($objProduct->cssID, true); $arrBuffer[] = array('cssID' => $arrCSS[0] != '' ? ' id="' . $arrCSS[0] . '"' : '', 'class' => trim('product ' . ($objProduct->isNew() ? 'new ' : '') . $arrCSS[1]), 'html' => $objProduct->generate($arrConfig), 'product' => $objProduct); } // HOOK: to add any product field or attribute to mod_iso_productlist template if (isset($GLOBALS['ISO_HOOKS']['generateProductList']) && is_array($GLOBALS['ISO_HOOKS']['generateProductList'])) { foreach ($GLOBALS['ISO_HOOKS']['generateProductList'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrBuffer = $objCallback->{$callback}[1]($arrBuffer, $arrProducts, $this->Template, $this); } } RowClass::withKey('class')->addCount('product_')->addEvenOdd('product_')->addFirstLast('product_')->addGridRows($this->iso_cols)->addGridCols($this->iso_cols)->applyTo($arrBuffer); $this->Template->products = $arrBuffer; }
public function testHtmlOutput() { $objResponse = new HtmlResponse('<!DOCTYPE html><html lang="en"><head></head><body></body></html>', 100); $this->assertSame(100, $objResponse->getStatusCode()); $this->assertSame((string) $objResponse, "HTTP/1.1 100 Continue\nContent-Length: 64\nContent-Type: text/html; charset=utf-8\n\n<!DOCTYPE html><html lang=\"en\"><head></head><body></body></html>"); }
/** * Compile item list. * * This function is specially designed so you can keep it in your child classes and only override findProperties(). * You will automatically gain item caching (see class property), grid classes, pagination and more. * * @return void */ protected function compile() { //Get products $arrProducts = $this->findProducts(); // No products found if (!is_array($arrProducts) || empty($arrProducts)) { $this->compileEmptyMessage(); return; } $arrBuffer = array(); $arrDefaultOptions = $this->getDefaultProductOptions(); foreach ($arrProducts as $objProduct) { $arrConfig = array('module' => $this, 'template' => $this->iso_list_layout ?: $objProduct->getRelated('type')->list_template, 'gallery' => $this->iso_gallery ?: $objProduct->getRelated('type')->list_gallery, 'buttons' => deserialize($this->iso_buttons, true), 'useQuantity' => $this->iso_use_quantity, 'jumpTo' => $this->findJumpToPage($objProduct)); if (\Environment::get('isAjaxRequest') && \Input::post('AJAX_MODULE') == $this->id && \Input::post('AJAX_PRODUCT') == $objProduct->getProductId()) { $objResponse = new HtmlResponse($objProduct->generate($arrConfig)); $objResponse->send(); } $objProduct->mergeRow($arrDefaultOptions); // Must be done after setting options to generate the variant config into the URL if ($this->iso_jump_first && \Haste\Input\Input::getAutoItem('product') == '') { \Controller::redirect($objProduct->generateUrl($arrConfig['jumpTo'])); } $arrCSS = deserialize($objProduct->cssID, true); $arrBuffer[] = array('cssID' => $arrCSS[0] != '' ? ' id="' . $arrCSS[0] . '"' : '', 'class' => trim('product ' . ($objProduct->isNew() ? 'new ' : '') . $arrCSS[1]), 'html' => $objProduct->generate($arrConfig), 'product' => $objProduct); } // HOOK: to add any product field or attribute to mod_iso_productlist template if (isset($GLOBALS['ISO_HOOKS']['generateProductList']) && is_array($GLOBALS['ISO_HOOKS']['generateProductList'])) { foreach ($GLOBALS['ISO_HOOKS']['generateProductList'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrBuffer = $objCallback->{$callback}[1]($arrBuffer, $arrProducts, $this->Template, $this); } } RowClass::withKey('class')->addCount('product_')->addEvenOdd('product_')->addFirstLast('product_')->addGridRows($this->iso_cols)->addGridCols($this->iso_cols)->applyTo($arrBuffer); $this->Template->products = $arrBuffer; }