protected function setSitemapProductImages(&$sitemap, $locale) { // Change timeout for this script ini_set('max_execution_time', Sitemap::getConfigValue('timeout', 30)); // Prepare query - get products URL $query = RewritingUrlQuery::create()->filterByView('product')->filterByRedirected(null)->filterByViewLocale($locale); // Join with visible products self::addJoinProductI18n($query); // Get products title & image file name $query->withColumn(ProductI18nTableMap::TITLE, 'PRODUCT_TITLE'); $query->addDescendingOrderByColumn(ProductImageTableMap::POSITION); $query->addGroupByColumn(RewritingUrlTableMap::VIEW_ID); $query->withColumn(ProductImageTableMap::FILE, 'PRODUCT_FILE'); // Execute query $results = $query->find(); // Get image generation configuration values $configValues = []; $configValues['width'] = Sitemap::getConfigValue('width'); $configValues['height'] = Sitemap::getConfigValue('height'); $configValues['quality'] = Sitemap::getConfigValue('quality', 75); $configValues['rotation'] = Sitemap::getConfigValue('rotation', 0); $configValues['resizeMode'] = Sitemap::getConfigValue('resize_mode', \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS); $configValues['bgColor'] = Sitemap::getConfigValue('background_color'); $configValues['allowZoom'] = Sitemap::getConfigValue('allow_zoom', false); // For each result, hydrate XML file /** @var RewritingUrl $result */ foreach ($results as $result) { // Generate image data $this->generateSitemapImage('product', $result, $configValues, $sitemap); } }
/** * Save data * * @return mixed|\Thelia\Core\HttpFoundation\Response */ public function saveAction() { if (null !== ($response = $this->checkAuth([AdminResources::MODULE], ["sitemap"], AccessManager::UPDATE))) { return $response; } $baseForm = $this->createForm("sitemap_config_form"); $errorMessage = null; // Get current edition language locale $locale = $this->getCurrentEditionLocale(); try { $form = $this->validateForm($baseForm); $data = $form->getData(); // Get resize mode switch ($data["resize_mode"]) { case 'none': $resizeMode = \Thelia\Action\Image::KEEP_IMAGE_RATIO; break; case 'crop': $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP; break; case 'borders': default: $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS; break; } // Save data Sitemap::setConfigValue('timeout', $data['timeout']); Sitemap::setConfigValue('width', $data['width']); Sitemap::setConfigValue('height', $data['height']); Sitemap::setConfigValue('quality', $data['quality']); Sitemap::setConfigValue('rotation', $data['rotation']); Sitemap::setConfigValue('resize_mode', $resizeMode); Sitemap::setConfigValue('background_color', $data['background_color']); Sitemap::setConfigValue('allow_zoom', $data['allow_zoom']); } catch (FormValidationException $ex) { // Invalid data entered $errorMessage = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], Sitemap::DOMAIN_NAME, $locale); } if (null !== $errorMessage) { // Mark the form as with error $baseForm->setErrorMessage($errorMessage); // Send the form and the error to the parser $this->getParserContext()->addForm($baseForm)->setGeneralError($errorMessage); } else { $this->getParserContext()->set("success", true); } return $this->defaultAction(); }
<?php require_once __DIR__ . '/vendor/autoload.php'; use Sitemap\Sitemap; $s = new Sitemap(); $s->addItem('http://blablabla.com'); $s->addItem('http://blablabla.com/123', '0.2'); $s->addItem('http://blablabla.com/234', 0.5, '2013-03-12'); $s->addItem('http://blablabla.com/345', 0.7, date('Y-m-d'), 'always'); die($s);