/** * Display the XML sitemap * @access public * @return void */ function display($tpl = null) { $document = $this->document; $document->setMimeEncoding('application/xml'); $session = JFactory::getSession(); // Call by cache handler get no params, so recover from model state if (!$tpl) { $tpl = $this->getModel()->getState('documentformat'); } $this->data = $this->get('SitemapData'); $this->cparams = $this->getModel()->getState('cparams'); // Transport wrapper $this->HTTPClient = new JMapHttp(null, $this->cparams); $this->outputtedLinksBuffer = array(); // Reload $this->outputtedVideosBuffer from previous session if process_status === run, AKA an ongoing JS AJAX precaching is running $this->outputtedVideosBuffer = $this->app->input->get('process_status', null) === 'run' ? $session->get('com_jmap.videos_buffer') : array(); $this->application = JFactory::getApplication(); $this->xslt = $this->getModel()->getState('xslt'); $this->videoApisEndpoints = array('youtube' => 'https://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=json', 'vimeo' => 'http://vimeo.com/api/v2/video/%s.json', 'dailymotion' => 'https://api.dailymotion.com/video/%s?fields=title,duration,description,thumbnail_360_url'); $uriInstance = JURI::getInstance(); $customHttpPort = trim($this->cparams->get('custom_http_port', '')); $getPort = $customHttpPort ? ':' . $customHttpPort : ''; $customDomain = trim($this->cparams->get('custom_sitemap_domain', '')); $getDomain = $customDomain ? rtrim($customDomain, '/') : rtrim($uriInstance->getScheme() . '://' . $uriInstance->getHost(), '/'); if ($this->cparams->get('append_livesite', true)) { $this->liveSite = rtrim($getDomain . $getPort, '/'); } else { $this->liveSite = null; } // Crawler live site management if ($this->cparams->get('sh404sef_multilanguage', 0) && JMapLanguageMultilang::isEnabled()) { $lang = '/' . $this->app->input->get('lang'); // Check if sh404sef insert language code param is off, otherwise the result would be doubled language chunk in liveSiteCrawler $sh404SefParams = JComponentHelper::getParams('com_sh404sef'); if ($sh404SefParams->get('shInsertLanguageCode', 0) || !$sh404SefParams->get('Enabled', 1)) { $lang = null; } $this->liveSiteCrawler = rtrim($getDomain . $getPort . $lang, '/'); } else { $this->liveSiteCrawler = rtrim($getDomain . $getPort, '/'); } // Add include path $this->addTemplatePath(JPATH_COMPONENT . '/views/sitemap/tmpl/videos'); $this->setLayout('default'); parent::display($tpl); // Assign $this->outputtedVideosBuffer for next session if process_status == start/run if (in_array($this->app->input->get('process_status', null), array('start', 'run'))) { $session->set('com_jmap.videos_buffer', $this->outputtedVideosBuffer); } // Delete $this->outputtedVideosBuffer session if process_status == end if ($this->app->input->get('process_status', null) === 'end') { $session->clear('com_jmap.videos_buffer'); } }
/** * Display the XML sitemap * @access public * @return void */ function display($tpl = null) { $document = $this->document; $document->setMimeEncoding('application/xml'); // Call by cache handler get no params, so recover from model state if (!$tpl) { $tpl = $this->getModel()->getState('documentformat'); } $this->data = $this->get('SitemapData'); $this->cparams = $this->getModel()->getState('cparams'); // Transport wrapper $this->HTTPClient = new JMapHttp(null, $this->cparams); $this->outputtedLinksBuffer = array(); $this->application = JFactory::getApplication(); $this->xslt = $this->getModel()->getState('xslt'); // Set regex for the images crawler $this->mainImagesRegex = $this->cparams->get('regex_images_crawler', 'advanced') == 'standard' ? '/(<img)([^>])*(src=["\']([^"\']+)["\'])([^>])*/i' : '/(<img)([^>])*(src=["\']?([^"\']+\\.(jpg|jpeg|gif|png))["\']?)([^>])*/i'; $uriInstance = JURI::getInstance(); $customHttpPort = trim($this->cparams->get('custom_http_port', '')); $getPort = $customHttpPort ? ':' . $customHttpPort : ''; $customDomain = trim($this->cparams->get('custom_sitemap_domain', '')); $getDomain = $customDomain ? rtrim($customDomain, '/') : rtrim($uriInstance->getScheme() . '://' . $uriInstance->getHost(), '/'); if ($this->cparams->get('append_livesite', true)) { $this->liveSite = rtrim($getDomain . $getPort, '/'); } else { $this->liveSite = null; } // Crawler live site management if ($this->cparams->get('sh404sef_multilanguage', 0) && JMapLanguageMultilang::isEnabled()) { $lang = '/' . $this->app->input->get('lang'); // Check if sh404sef insert language code param is off, otherwise the result would be doubled language chunk in liveSiteCrawler $sh404SefParams = JComponentHelper::getParams('com_sh404sef'); if ($sh404SefParams->get('shInsertLanguageCode', 0) || !$sh404SefParams->get('Enabled', 1)) { $lang = null; } $this->liveSiteCrawler = rtrim($getDomain . $getPort . $lang, '/'); } else { $this->liveSiteCrawler = rtrim($getDomain . $getPort, '/'); } $this->setLayout('default'); parent::display($tpl); }
} $additionalQueryStringParams = trim($additionalQueryStringParams, ','); if ($additionalQueryStringParams) { $additionalQueryStringParams = '&' . preg_replace('/,\\s*/i', '&', $additionalQueryStringParams); $additionalQueryStringParams = preg_replace('/\\s+/i', '', $additionalQueryStringParams); } $targetOption = $this->source->chunks->option; $targetViewName = $this->sourceparams->get('view', null); $targetView = $targetViewName ? '&view=' . $targetViewName : null; // Supported adapters for Router Helper $supportedRouterHelperAdapters = array('com_k2' => false, 'com_easyblog' => false, 'com_contact' => false, 'com_weblinks' => false, 'com_newsfeeds' => false, 'com_hwdmediashare' => false, 'com_eventbooking' => false, 'com_edocman' => false, 'com_phocadownload' => false, 'com_ezrealty' => false, 'com_iproperty' => false, 'com_djcatalog2' => false, 'com_jomestate' => false, 'com_eshop' => false, 'com_jomdirectory' => false); $supportedRouterHelperAdaptersPaths = array('com_eventbooking' => 'helper', 'com_edocman' => 'helper'); $supportedRouterHelperAdaptersFiles = array('com_easyblog' => 'router'); // Adapter for com_eshop if ($targetOption == 'com_eshop') { if (version_compare(JVERSION, '3.0', 'ge') && JMapLanguageMultilang::isEnabled()) { $supportedRouterHelperAdaptersFiles['com_eshop'] = 'routev3'; } } if (array_key_exists($targetOption, $supportedRouterHelperAdapters)) { $folderPath = array_key_exists($targetOption, $supportedRouterHelperAdaptersPaths) ? $supportedRouterHelperAdaptersPaths[$targetOption] : 'helpers'; $filePath = array_key_exists($targetOption, $supportedRouterHelperAdaptersFiles) ? $supportedRouterHelperAdaptersFiles[$targetOption] : 'route'; if (file_exists(JPATH_SITE . '/components/' . $targetOption . '/' . $folderPath . '/' . $filePath . '.php')) { include_once JPATH_SITE . '/components/' . $targetOption . '/' . $folderPath . '/' . $filePath . '.php'; $supportedRouterHelperAdapters[$targetOption] = true; $liveSite = $this->liveSite; } } // Fallback identifiers $titleIdentifier = !empty($this->source->chunks->titlefield_as) ? $this->source->chunks->titlefield_as : $this->source->chunks->titlefield; $idIdentifier = !empty($this->source->chunks->idfield_as) ? $this->source->chunks->idfield_as : $this->source->chunks->id;
/** * Route save single article to the corresponding SEF link * * @access private * @return string */ private function routeArticleToSefMenu($articleID, $catID, $language, $article) { // Try to route the article to a single article menu item view $helperRouteClass = $this->context['class']; $classMethod = $this->context['method']; // Route helper native by component, com_content, com_k2 if (!isset($this->context['routing'])) { $articleHelperRoute = $helperRouteClass::$classMethod($articleID, $catID, $language); } else { // Route helper universal JSitemap, com_zoo $articleHelperRoute = $helperRouteClass::$classMethod($article->option, $article->view, $article->id, $article->catid, null); if ($articleHelperRoute) { $articleHelperRoute = '?Itemid=' . $articleHelperRoute; } } // Extract Itemid from the helper routed URL $extractedItemid = preg_match('/Itemid=\\d+/i', $articleHelperRoute, $result); if (isset($result[0])) { // Get uri instance avoidng subdomains already included in the routing chunks $uriInstance = JUri::getInstance(); $resourceLiveSite = rtrim($uriInstance->getScheme() . '://' . $uriInstance->getHost(), '/'); $extractedItemid = $result[0]; $siteRouter = JRouterSite::getInstance('site', array('mode' => JROUTER_MODE_SEF)); $articleMenuRouted = $siteRouter->build('?' . $extractedItemid)->toString(); // Check if multilanguage is enabled if (JMapLanguageMultilang::isEnabled()) { if ($language != '*') { // New language manager instance $languageManager = JMapLanguageMultilang::getInstance($language); } else { // Get the default language tag // New language manager instance $languageManager = JMapLanguageMultilang::getInstance(); } // Extract the language tag $localeTag = $languageManager->getLocale(); $sefTag = $localeTag[4]; $articleMenuRouted = str_replace('/administrator', '/' . $sefTag, $articleMenuRouted); } else { $articleMenuRouted = str_replace('/administrator', '', $articleMenuRouted); } $articleMenuRouted = preg_match('/http/i', $articleMenuRouted) ? $articleMenuRouted : $resourceLiveSite . '/' . ltrim($articleMenuRouted, '/'); return $articleMenuRouted; } else { // Check if routing is valid otherwise throw exception throw new RuntimeException(JText::_('COM_JMAP_AUTOPING_ERROR_NOSEFROUTE_FOUND')); } }
/** * Override Language instantiator * * @access public * @return JLanguage The Language object. */ public static function getInstance($lang = null, $debug = false) { $conf = JFactory::getConfig(); if (is_null($lang)) { $locale = $conf->get('config.language'); } else { $locale = $lang; } $langInstance = new JMapLanguageMultilang($locale); $langInstance->setDebug($conf->get('config.debug_lang')); return $langInstance; }
/** * Postprocessing at runtime for third party extensions subqueries * that generate data for nested cats tree * New data will be appended to catsTree property of resultSourceObject * * @access protected * @param Object $source * @return array An array of objects, one for products by cat and one for catChildren by cat, also assigned to $source properties to be used inside view */ protected function subQueriesPostProcessor($source, $manifest = null) { // Replace these variables reading from manifest json file if ($manifest) { $manifestConfiguration = json_decode($manifest); } else { $manifestConfiguration = $this->loadManifest($source->chunks->option); if ($manifestConfiguration === false) { return false; } } // Error decoding configuration object, exit and fallback to standard indenting if (!is_object($manifestConfiguration)) { throw new JMapException(JText::sprintf('COM_JMAP_ERROR_MULTILEVELCATS_MANIFEST_ERROR', $source->name), 'notice'); } // Detect if cat recoursion is enabled if ($manifestConfiguration->catrecursion) { // Enable cat recursion for this data source $source->catRecursion = true; } else { return false; } // Recursion type not adiacency, already managed natively by raw sql query compiler and standard indenting by level value if (!in_array($manifestConfiguration->recursion_type, array('adiacency', 'multiadiacency'))) { return false; } // Init query chunks $selectCatName = null; $validCategoryCondition = null; $categoriesJoinCondition = null; $additionalCategoriesTableCondition = null; $validCategory2CategoryCondition = null; $asCategoryTableIdField = $manifestConfiguration->category_table_id_field; $asCategoryTableNameField = str_replace('{langtag}', $this->langTag, $manifestConfiguration->category_table_name_field); // Category table $categoriesTable = $manifestConfiguration->categories_table; // SELECT for catname $selectCatName = $this->_db->quoteName($categoriesTable) . "." . $this->_db->quoteName($asCategoryTableNameField) . " AS " . $this->_db->quoteName('catname'); // Parent field $asCategoryParentIdField = $manifestConfiguration->parent_field; // Child field #Optional $asCategoryChildIdField = $manifestConfiguration->child_field; // Categories 2 categories table $category2categoryTable = $manifestConfiguration->category2category_table; // Valid category condition if ($categoryConditions = $this->fetchAutoInjectDefaultWhereFields($categoriesTable, $manifestConfiguration, $source)) { $validCategoryCondition = "\n WHERE " . implode("\n AND ", $categoryConditions); } // Detect type of adiacency set model for database tables switch ($manifestConfiguration->recursion_type) { case 'multiadiacency': // Additional categories table required for some weird reason from 3PD developers // Field cat id su record entities that MUST match, used by multi adiacency instead of jsitemap_category and must be needed from route string, is not unset if (isset($manifestConfiguration->additional_categories_table) && isset($manifestConfiguration->additional_categories_table_on_catid_field)) { if (strpos($manifestConfiguration->additional_categories_table, '$$$')) { $additionalCategoriesTable = str_replace('$$$', '_' . $this->siteLanguageRFC, $manifestConfiguration->additional_categories_table); // Check if $additionalCategoriesTable exists otherwise fallback and replace again with default site language hoping that table exists $checkTableQuery = "SELECT 1 FROM " . $this->_db->quoteName($additionalCategoriesTable); $tableExists = $this->_db->setQuery($checkTableQuery)->loadResult(); if (!$tableExists) { $additionalCategoriesTable = str_replace('$$$', '_' . $this->fallbackDefaultLanguageRFC, $manifestConfiguration->additional_categories_table); } } else { $additionalCategoriesTable = $manifestConfiguration->additional_categories_table; } $additionalCategoriesTableOnCatidField = $manifestConfiguration->additional_categories_table_on_catid_field; $selectCatName = $this->_db->quoteName($additionalCategoriesTable) . "." . $this->_db->quoteName($asCategoryTableNameField) . " AS " . $this->_db->quoteName('catname'); if (isset($manifestConfiguration->additional_categories_table_on_fkcatid_field)) { $additionalCategoriesTableOnFKCatidField = $manifestConfiguration->additional_categories_table_on_fkcatid_field; $categoriesJoinCondition = "\n INNER JOIN " . $this->_db->quoteName($additionalCategoriesTable) . "\n ON " . $this->_db->quoteName($categoriesTable) . "." . $this->_db->quoteName($additionalCategoriesTableOnCatidField) . " = " . $this->_db->quoteName($additionalCategoriesTable) . "." . $this->_db->quoteName($additionalCategoriesTableOnFKCatidField); } else { $categoriesJoinCondition = "\n INNER JOIN " . $this->_db->quoteName($additionalCategoriesTable) . "\n ON " . $this->_db->quoteName($categoriesTable) . "." . $this->_db->quoteName($additionalCategoriesTableOnCatidField) . " = " . $this->_db->quoteName($additionalCategoriesTable) . "." . $this->_db->quoteName($additionalCategoriesTableOnCatidField); } } if (isset($manifestConfiguration->additional_categories_table_condition)) { $languageID = JMapLanguageMultilang::loadLanguageID($this->langTag); $additionalCategoriesTableCondition = str_replace('$$$', $languageID, "\n WHERE " . $manifestConfiguration->additional_categories_table_condition); } if (isset($manifestConfiguration->additional_and_categories_table_condition)) { $additionalCategoriesTableCondition = str_replace('$$$', $this->_db->quote($this->langTag), "\n AND " . $manifestConfiguration->additional_and_categories_table_condition); } // Valid category 2 category condition if (isset($manifestConfiguration->category2category_condition)) { if (!empty($source->chunks->where1_maintable) && !empty($source->chunks->where1_value_maintable) && strpos($manifestConfiguration->category2category_condition, '$$$')) { if (strpos($source->chunks->where1_value_maintable, ',')) { $validCategory2CategoryCondition = str_replace('@', ' IN(', $manifestConfiguration->category2category_condition); $validCategory2CategoryCondition = str_replace('$$$', $source->chunks->where1_value_maintable . ')', $validCategory2CategoryCondition); } else { $validCategory2CategoryCondition = str_replace('@', '=', $manifestConfiguration->category2category_condition); $validCategory2CategoryCondition = str_replace('$$$', $source->chunks->where1_value_maintable, $validCategory2CategoryCondition); } } elseif (strpos($manifestConfiguration->category2category_condition, '$$$')) { $validCategory2CategoryCondition = null; } else { $validCategory2CategoryCondition = $manifestConfiguration->category2category_condition; } } $where = $validCategory2CategoryCondition ? "\n WHERE " . $validCategory2CategoryCondition : null; $query = "SELECT " . $this->_db->quoteName($asCategoryParentIdField) . " AS " . $this->_db->quoteName('parent') . "," . $this->_db->quoteName($asCategoryChildIdField) . " AS " . $this->_db->quoteName('child') . "\n FROM " . $this->_db->quoteName($category2categoryTable) . $where; $totalItemsCatsTree = $this->_db->setQuery($query)->loadAssocList('child'); // Cancel post processor effect if db error detected and fallback on standard one level tree if ($this->_db->getErrorNum()) { return false; } break; case 'adiacency': default: $query = "SELECT " . $this->_db->quoteName($asCategoryParentIdField) . " AS " . $this->_db->quoteName('parent') . "," . $this->_db->quoteName($asCategoryChildIdField) . " AS " . $this->_db->quoteName('child') . "\n FROM " . $this->_db->quoteName($category2categoryTable); $totalItemsCatsTree = $this->_db->setQuery($query)->loadAssocList('child'); // Cancel post processor effect if db error detected and fallback on standard one level tree if ($this->_db->getErrorNum()) { return false; } break; } // First pass organize items by cats $itemsByCats = array(); if (count($source->data)) { foreach ($source->data as $item) { $itemsByCats[$item->jsitemap_category_id][] = $item; } } // ASSIGNMENT TO SOURCE $source->itemsByCat = $itemsByCats; // Grab total items cats IDs/Names and inject auto fields $query = "SELECT DISTINCT " . $this->_db->quoteName($categoriesTable) . "." . $this->_db->quoteName($asCategoryTableIdField) . " AS " . $this->_db->quoteName('id') . "," . $selectCatName . "\n FROM " . $this->_db->quoteName($categoriesTable) . $categoriesJoinCondition . $validCategoryCondition . $additionalCategoriesTableCondition; $totalItemsCats = $this->_db->setQuery($query)->loadAssocList(); // Cancel post processor effect if db error detected and fallback on standard one level tree if ($this->_db->getErrorNum()) { return false; } // Second pass organize categories by parent - children $childrenCats = array(); if (count($totalItemsCats)) { foreach ($totalItemsCats as $childCat) { $parentCat = $totalItemsCatsTree[$childCat['id']]['parent']; $childrenCats[$parentCat][] = $childCat; } } // ASSIGNMENT TO SOURCE $source->catChildrenByCat = $childrenCats; return array($itemsByCats, $childrenCats); }