sitemap.php 64.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
<?php
// namespace components\com_jmap\models;
/**
 * @package JMAP::SITEMAP::components::com_jmap
 * @subpackage models
 * @author Joomla! Extensions Store
 * @copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );

/**
 * Main sitemap model public responsibilities interface
 *
 * @package JMAP::SITEMAP::components::com_jmap
 * @subpackage models
 */
interface IJMapModelSitemap {
	/**
	 * Get the Data
	 * @access public
	 * @return array
	 */
	public function getSitemapData();
	
	/**
	 * Get the component params width view override/merge
	 * @access public
	 * @return Object
	 */
	public function getComponentParams();
}

/**
 * CPanel export XML sitemap responsibility
 *
 * @package JMAP::CPANEL::administrator::components::com_jmap
 * @subpackage models
 * @since 1.0
 */
interface IJMapModelExportable {
	/**
	 * Export XML file for sitemap
	 *
	 * @access public
	 * @param string $contents
	 * @param string $fileNameSuffix
	 * @param string $fileNameFormat
	 * @param string $fileNameLanguage
	 * @param string $fileNameDatasetFilter
	 * @param string $fileNameItemidFilter
	 * @param string $mimeType
	 * @param boolean $isFile
	 * @return boolean
	 */
	public function exportXMLSitemap($contents, $fileNameSuffix, $fileNameFormat, $fileNameLanguage, $fileNameDatasetFilter, $fileNameItemidFilter, $mimeType, $isFile = false);
}

/**
 * Main sitemap model class <<testable_behavior>>
 *
 * @package JMAP::SITEMAP::components::com_jmap
 * @subpackage models
 * @since 1.0
 */
class JMapModelSitemap extends JMapModel implements IJMapModelSitemap, IJMapModelExportable {
	/**
	 * Fallback default site language
	 * @access private
	 * @var string
	 */
	private $fallbackDefaultLanguage;
	
	/**
	 * Fallback default site language RFC format
	 * @access private
	 * @var string
	 */
	private $fallbackDefaultLanguageRFC;
	
	/**
	 * Default site language
	 * @access private
	 * @var string
	 */
	private $langTag;
	
	/**
	 * Default site language
	 * @access private
	 * @var string
	 */
	private $siteLanguageRFC;
	
	/**
	 * Document formats
	 * @access private
	 * @var array
	 */
	private $documentFormat;
	
	/**
	 * Component params with view overrides/merge
	 * @access private
	 * @var array
	 */
	private $cparams;
	
	/**
	 * Supported tables for options components supported to generate
	 * 3PD Google News sitemap
	 * @access private
	 * @var array
	 */
	private $supportedGNewsTablesOptions;
	
	/**
	 * Access level
	 * @access private
	 * @var string
	 */
	private $accessLevel = array();
	
	/**
	 * Main data structure
	 * @access private
	 * @var array
	 */
	private $data = array (); 
	
	/**
	 * Sources array
	 * @access private
	 * @var array
	 */
	private $sources = array (); 
	
	/**
	 * RSS extesions manifest supported
	 * @access private
	 * @var Object
	 */
	private $rssExtensionsManifest;
	
	/**
	 * Calculated limit start for source data query during a precaching process
	 * @access public
	 * @var int
	 */
	public $limitStart;
	
	/**
	 * Calculated limit rows for source data query during a precaching process
	 * @access public
	 * @var int
	 */
	public $limitRows;
	
	/**
	 * Send as attachment download
	 * 
	 * @access public
	 * @param String $contents
	 * @param String $filename Nome del file esportato
	 * @param String $mimeType Mime Type dell'attachment
	 * @param boolean $isFile Se trattare il contenuto come file name o content pronti
	 * @return void
	 */
	private function sendAsBinary($contents, $filename, $mimeType, $isFile = false) {
		if($isFile) {
			$fsize = @filesize ( $contents );
		} else {
			$fsize = strlen($contents);
		}
	
		// required for IE, otherwise Content-disposition is ignored
		if (ini_get ( 'zlib.output_compression' )) {
			ini_set ( 'zlib.output_compression', 'Off' );
		}
		header ( "Pragma: public" );
		header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
		header ( "Expires: 0" );
		header ( "Content-Transfer-Encoding: binary" );
		header ( 'Content-Disposition: attachment;' . ' filename="' . $filename . '";' . ' size=' . $fsize . ';' ); //RFC2183
		header ( "Content-Type: " . $mimeType); // MIME type
		header ( "Content-Length: " . $fsize );
		if (! ini_get ( 'safe_mode' )) { // set_time_limit doesn't work in safe mode
			@set_time_limit ( 0 );
		}
		
		if(!$isFile) {
			echo $contents; 
		} else {
			$this->readfile_chunked ( $contents );
		}
	
		exit();
	}
	
	/**
	 * Read and send in the output stream the contents of the file in chunks,
	 * Resolving the problems of limitations related to the normal readfile
	 * 
	 * @access private
	 * @param string $nomefile
	 * @return boolean
	 */
	private function readfile_chunked($filename) {
		$chunksize = 1 * (1024 * 1024); // how many bytes per chunk
		$buffer = '';
		$cnt = 0;
		$handle = fopen ( $filename, 'rb' );
		if ($handle === false) {
			return false;
		}
		while ( ! feof ( $handle ) ) {
			$buffer = fread ( $handle, $chunksize );
			echo $buffer;
			@ob_flush ();
			flush ();
		}
		$status = fclose ( $handle );
		return $status;
	}
	
	/**
	 * Pagebreaks detection
	 * 
	 * @access private
	 * @param Object& $article
	 * @return boolean
	 */
	private function addPagebreaks(&$article) {
		$matches = array ();
		if (preg_match_all ( '/<hr\s*[^>]*?(?:(?:\s*alt="(?P<alt>[^"]+)")|(?:\s*title="(?P<title>[^"]+)"))+[^>]*>/i', $article->completetext, $matches, PREG_SET_ORDER )) {
			foreach ( $matches as $i=>$match ) {
				if (strpos ( $match [0], 'class="system-pagebreak"' ) !== FALSE) {
					if (@$match ['alt']) {
						$title = stripslashes ( $match ['alt'] );
					} elseif (@$match ['title']) {
						$title = stripslashes ( $match ['title'] );
					} else {
						$title = JText::sprintf ( 'Page #', $i );
					}
					$article->expandible[] = $title;
				}
			}
			return true;
		}
		return false;
	}
	
	/**
	 * Preprocessing at runtime for third party extensions generated query
	 * General purpouse function to fil gaps of 3PD extensions at runtime
	 * Maybe in future could migrate to configurable JSON manifest as for wizard
	 * 
	 * @access private
	 * @param Object $source
	 * @param string $query
	 * @param Object $params
	 * @return string The processed query SQL string
	 */
	private function runtimePreProcessing($query, $resultSourceObject) {
		// Switch data source option name
		$sqlqueryManaged = $resultSourceObject->chunks;
		$params = $resultSourceObject->params;
		$option = $resultSourceObject->chunks->option;
		
		switch ($sqlqueryManaged->option) {
			case 'com_virtuemart':
				// If site user language not match default for generated query and is VM 2 with extended lang tables
				if(!stristr($sqlqueryManaged->table_maintable, $this->siteLanguageRFC) && stristr($sqlqueryManaged->table_maintable, 'virtuemart') && JMapLanguageMultilang::isEnabled()) {
					// Find language with which generated query has been generated
					$maintableChunked = explode('_', $sqlqueryManaged->table_maintable);
					$langReverseChunks = array();
					$langReverseChunks[] = array_pop($maintableChunked);
					$langReverseChunks[] = array_pop($maintableChunked);
					$originalLang = array_reverse($langReverseChunks);
					$originalLang = implode('_', $originalLang);
					
					// Site language has been changed from default for which query has been generated, so process
					$processedQuery = preg_replace('/(#__virtuemart.*)(_'.$originalLang.')/iU', '$1_'.$this->siteLanguageRFC.'$3', $query);
					
					// Now test if admin has created virtuemart 2 tables for the site user chosen language otherwise proceed with same of generated query
					$this->_db->setQuery($processedQuery);
					try {
						if($this->_db->execute()) {
							$query = $processedQuery;
						}
					} catch (Exception $e) {
						// No exception throw, just go on
					}
				}
			break;
			
			case 'com_jshopping':
				// If site user language not match default for generated query and is Joomshopping we can go on to replace language value
				if(!stristr($sqlqueryManaged->titlefield, $this->langTag) && stristr($sqlqueryManaged->table_maintable, 'jshopping')) {
					// Find deafult site language with which raw query has been generated
					$maintableChunked = explode('_', $sqlqueryManaged->titlefield);
					$originalLang = array_pop($maintableChunked);

					// Site language has been changed from default for which query has been generated, so process
					$processedQuery = preg_replace('/(name)(_'.$originalLang.')/iU', '$1_'.$this->langTag.'$3', $query);
					$resultSourceObject->chunks->titlefield = str_replace($originalLang, $this->langTag, $resultSourceObject->chunks->titlefield);
					$resultSourceObject->chunks->orderby_maintable = str_replace($originalLang, $this->langTag, $resultSourceObject->chunks->orderby_maintable);
					$resultSourceObject->chunks->field_select_jointable2 = @str_replace($originalLang, $this->langTag, $resultSourceObject->chunks->field_select_jointable2);

					// Now test if admin has created virtuemart 2 tables for the site user chosen language otherwise proceed with same of generated query
					$checkSafeQuery = "SHOW COLUMNS FROM " . $this->_db->quoteName($sqlqueryManaged->table_maintable);
					$this->_db->setQuery($checkSafeQuery);
					$columnsArray = $this->_db->loadColumn();
					if(in_array('name_' . $this->langTag, $columnsArray)) {
						$query = $processedQuery;
					}
				}
			break;
			
			case 'com_j2store':
				// Leave untouched
				break;
		
			// Preprocessing with generic tasks for all extensions
			default:
				// Only if multilanguage is not currently enabled, switch query to select all disregarding language filter 
				if(!JMapLanguageMultilang::isEnabled() && stristr($query, '{langtag}')) {
					// Do replacement to avoid language filtering
					$toReplaceString = "{langtag} OR " . $this->_db->quoteName($sqlqueryManaged->table_maintable) . "." . 
														 $this->_db->quoteName('language') . " != ''";
					$query = str_replace("{langtag}", $toReplaceString, $query);
				}
				// Avoid access filtering if ACL disabled
				if($params->get('disable_acl') === 'disabled' && stristr($query, '{aid}')) {
					$toReplaceString = ">= 0";
					$query = str_replace("IN {aid}", $toReplaceString, $query);
				}
		}
		
		// Manage preprocessing query for multi level categorization recursion types level/adiacency/multiadiacency. This let avoid to change backend wizard manifests
		$hasJSitemapCategoryId = false;
		if($params->get('multilevel_categories', 0) && $this->hasCategorization($resultSourceObject)) {
			$manifestConfiguration = $this->loadManifest ($option);
			// Error decoding configuration object, exit and fallback to standard indenting
			if(is_object($manifestConfiguration) && isset($manifestConfiguration->recursion_type) && $manifestConfiguration->recursion_type == 'level') {
				$toReplaceString = "SELECT " . 
									$this->_db->quoteName($manifestConfiguration->categories_table) . "." . 
									$this->_db->quoteName($manifestConfiguration->level_field) . 
									" AS " . $this->_db->quoteName('jsitemap_level') . ", ";
				$query = preg_replace("/SELECT/", $toReplaceString, $query, 1);
				$resultSourceObject->catRecursion = true;
				$resultSourceObject->recursionType = $manifestConfiguration->recursion_type;
			} elseif (is_object($manifestConfiguration) && isset($manifestConfiguration->recursion_type) && $manifestConfiguration->recursion_type == 'adiacency') {
				$toReplaceString = "SELECT " .
									$this->_db->quoteName($manifestConfiguration->categories_table) . "." .
									$this->_db->quoteName($manifestConfiguration->category_table_id_field) .
									" AS " . $this->_db->quoteName('jsitemap_category_id') . ", ";
				$query = preg_replace("/SELECT/", $toReplaceString, $query, 1);
				$resultSourceObject->catRecursion = true;
				$resultSourceObject->recursionType = $manifestConfiguration->recursion_type;
				$hasJSitemapCategoryId = true;
			} elseif (is_object($manifestConfiguration) && 
					  isset($manifestConfiguration->recursion_type) && 
					  $manifestConfiguration->recursion_type == 'multiadiacency' && 
					  !preg_match('/categor|cats|catg/i', $resultSourceObject->chunks->table_maintable)) {
				$toReplaceString = "SELECT " .
									$this->_db->quoteName($manifestConfiguration->item2category_table) . "." .
									$this->_db->quoteName($manifestConfiguration->item2category_catid_field) .
									" AS " . $this->_db->quoteName('jsitemap_category_id') . ", ";
				$query = preg_replace("/SELECT/", $toReplaceString, $query, 1);
				$resultSourceObject->catRecursion = true;
				$resultSourceObject->recursionType = $manifestConfiguration->recursion_type;
				$hasJSitemapCategoryId = true;
			} elseif (is_object($manifestConfiguration) &&
					  isset($manifestConfiguration->recursion_type) &&
					  $manifestConfiguration->recursion_type == 'multiadiacency' &&
					  preg_match('/categor|cats|catg/i', $resultSourceObject->chunks->table_maintable)) {
				$toReplaceString = "SELECT " .
									$this->_db->quoteName($manifestConfiguration->categories_table) . "." .
									$this->_db->quoteName($manifestConfiguration->category_table_id_field) .
									" AS " . $this->_db->quoteName('jsitemap_category_id') . ", ";
				$query = preg_replace("/SELECT/", $toReplaceString, $query, 1);
				$resultSourceObject->catRecursion = true;
				$resultSourceObject->recursionType = $manifestConfiguration->recursion_type;
				$hasJSitemapCategoryId = true;
			}
		}
		
		// Not just injected jsitemap_category_id for the multilevel, param $guessItemid active and not category type data source itself
		$guessItemid = $params->get('guess_sef_itemid', 0);
		if(	!$hasJSitemapCategoryId
			&& $guessItemid
			&& $this->hasCategorization($resultSourceObject, true)
			&& !preg_match('/categor|cats|catg/i', $resultSourceObject->chunks->table_maintable)
			&& $routeManifest = $this->loadRouteManifest($option)) {
			$toReplaceString = "SELECT " .
							   $this->_db->quoteName($routeManifest->categories_table) . "." .
							   $this->_db->quoteName($routeManifest->categories_table_id_field) .
							   " AS " . $this->_db->quoteName('jsitemap_category_id') . ", ";
			$query = preg_replace("/SELECT/", $toReplaceString, $query, 1);
		}
		
		return $query;
	}
	
	/**
	 * Preprocessing at runtime for native content and third party extensions
	 * for the exclusive RSS format feed, thanks to adapter manifest allow to
	 * inject the extra field to extract the feed description
	 *
	 * @access private
	 * @param string $keyIndexTable The extension key to get the field from the manifest
	 * @param string $query The query to process
	 * @return string The processed query SQL string
	 */
	private function runtimeRssPreProcessing($keyIndexTable, $query) {
		// Get the description field based on table key
		$descField = $this->rssExtensionsManifest->{$keyIndexTable};

		$toReplaceString = "SELECT " .
						   $this->_db->quoteName($keyIndexTable) . "." .
						   $this->_db->quoteName($descField) .
						   " AS " . $this->_db->quoteName('jsitemap_rss_desc') . ", ";
		$query = preg_replace("/SELECT/", $toReplaceString, $query, 1);

		return $query;
	}
	
	/**
	 * sort a menu view
	 *
	 * @param
	 *        	array the menu
	 * @return array the sorted menu
	 */
	private function sortMenu($m, &$sourceParams) {
		$rootlevel = array ();
		$sublevels = array ();
		$newmenuitems = array();
		$r = 0;
		$s = 0;
		foreach ( $m as $item ) {
			if ($item->parent == 1) {
				// rootlevel
				$item->ebene = 0;
				$rootlevel [$r] = $item;
				$r ++;
			} else {
				// sublevel
				$item->ebene = 1;
				$sublevels [$s] = $item;
				$s ++;
			}
		}
		$maxlevels = $sourceParams->get ( 'maxlevels', '5' );
		$z = 0;
		if ($s != 0 and $maxlevels != 0) {
			foreach ( $rootlevel as $elm ) {
				$newmenuitems [$z] = $elm;
				$z ++;
				$this->sortMenuRecursive ( $z, $elm->id, $sublevels, 1, $maxlevels, $newmenuitems );
			}
		} else {
			$newmenuitems = $rootlevel;
		}
		return $newmenuitems;
	}
	
	/**
	 * sort a menu view Recursive through the tree
	 *
	 * @param
	 *        	int element number to work with
	 * @param
	 *        	int the parent id
	 * @param
	 *        	array the sublevels
	 * @param
	 *        	int the level
	 * @param
	 *        	int the maximun depth for the search
	 * @param
	 *        	array new menu
	 */
	private function sortMenuRecursive(&$z, $id, $sl, $ebene, $maxlevels, &$nm) {
		if ($ebene > $maxlevels) {
			return true;
		}
		foreach ( $sl as $selm ) {
			if ($selm->parent == $id) {
				$selm->ebene = $ebene;
				$nm [$z] = $selm;
				$z ++;
				$nebene = $ebene + 1;
				$this->sortMenuRecursive ( $z, $selm->id, $sl, $nebene, $maxlevels, $nm );
			}
		}
		return true;
	}
	 
	/**
	 * Get the Data for a view
	 * 
	 * @access private
	 * @param object $source
	 * @param array $accessLevels
	 * 
	 * @return Object
	 */
	private function getSourceData($source, $accessLevels) {
		// Create di un nuovo result source object popolato delle properties necessarie alla view e degli items recuperati da DB
		$resultSourceObject = new stdClass ();
		$resultSourceObject->id = $source->id;
		$resultSourceObject->name = $source->name;
		$resultSourceObject->type = $source->type;
		if($source->sqlquery_managed) {
			$resultSourceObject->chunks = json_decode($source->sqlquery_managed);
		}
		
		// If sitemap format is gnews, allow only content data source and 3PD user data source that are supported as compatible, avoid calculate unuseful data and return immediately
		if($this->documentFormat === 'gnews') {
			if($source->type === 'menu') {
				return false;
			}
			if($source->type === 'user') {
				if(isset($resultSourceObject->chunks)) {
					if(!in_array($resultSourceObject->chunks->table_maintable, $this->supportedGNewsTablesOptions)) {
						return false;
					}
				}
			}
		}
		
		// If sitemap format is rss, allow only content data source and 3PD user data source that are supported as compatible, avoid calculate unuseful data and return immediately
		if($this->documentFormat === 'rss') {
			if($source->type === 'menu' || $source->type === 'links') {
				return false;
			}
			// Load always manifest, both content and third party data sources
			$this->rssExtensionsManifest = $this->loadManifest('rss');

			// If third party data sources check if it's supported, otherwise return false
			if($source->type === 'user' && isset($resultSourceObject->chunks)) {
				// Add dynamic Virtuemart
				$vmProperty = '#__virtuemart_products_' . $this->siteLanguageRFC;
				$this->rssExtensionsManifest->{$vmProperty} = 'product_desc';

				// Skip extensions not supported for RSS feed generation
				if(!property_exists($this->rssExtensionsManifest, $resultSourceObject->chunks->table_maintable)) {
					return false;
				}
			}
		}
		
		// Already a JRegistry object! Please note object cloning to avoid reference overwriting!
		// Component -> menu view specific level params override
		$resultSourceObject->params = clone($this->cparams); 
		// Item specific level params override
		$resultSourceObject->params->merge(new JRegistry($source->params ));
		
		// Ensure the current datasource is enabled for the current sitemap format otherwise skip processing
		if(!$resultSourceObject->params->get('htmlinclude', 1) && $this->documentFormat == 'html') {
			return false;
		}
		if(!$resultSourceObject->params->get('xmlinclude', 1) && $this->documentFormat == 'xml') {
			return false;
		}
		if(!$resultSourceObject->params->get('xmlimagesinclude', 1) && $this->documentFormat == 'images') {
			return false;
		}
		if(!$resultSourceObject->params->get('xmlmobileinclude', 1) && $this->documentFormat == 'mobile') {
			return false;
		}
		if(!$resultSourceObject->params->get('gnewsinclude', 1) && $this->documentFormat == 'gnews') {
			return false;
		}
		if(!$resultSourceObject->params->get('rssinclude', 1) && $this->documentFormat == 'rss') {
			return false;
		}
		
		// ACL filtering
		$disableAcl = $resultSourceObject->params->get('disable_acl');

		$sourceItems = array();
		switch ($source->type) {
			case 'user':
				// Get the language param for the user data source and ensure that it's all langs or match the current language, if not skip getting data
				$languageTag = JMapLanguageMultilang::getCurrentSefLanguage();
				$dataSourceLanguage = $resultSourceObject->params->get('datasource_language', '*');
				if($dataSourceLanguage != '*' && ($languageTag != $dataSourceLanguage)) {
					// Detected a precaching call, set 0 affected rows to complete correctly the precaching process just now
					if($this->limitRows) {
						$this->setState('affected_rows', 0);
					}
					break;
				}
				
				$query = $source->sqlquery;
				$debugMode = $resultSourceObject->params->get('debug_mode', 0);
				// Do runtime preprocessing if any for selected data source extension
				$query = $this->runtimePreProcessing($query, $resultSourceObject);
				// Se la raw query  stata impostata
				if($query) {
					$query = str_replace('{aid}', '(' . implode(',', $accessLevels) . ')', $query);
					$query = str_replace('{langtag}', $this->_db->quote($this->langTag), $query);
					$query = str_replace('{languagetag}', $this->_db->quote($this->langTag), $query);
					$query = str_replace('{languagetagrfc}', $this->siteLanguageRFC, $query);
					
					// Manage for latest months placeholder if found one
					if(preg_match("/'?{(\d+)months}'?/i", $query, $matches)) {
						$minValidCreatedDate = gmdate ( "Y-m-d H:i:s", strtotime ( "-" . $matches[1] . " months", time()));
						// All items need to be created after the minimum valid created date
						$query = preg_replace("/'?{(\d+)months}'?/i", $this->_db->quote($minValidCreatedDate), $query);
					}
					
					// Runtime preprocessing for RSS description field
					if($this->documentFormat === 'rss') {
						$query = $this->runtimeRssPreProcessing($resultSourceObject->chunks->table_maintable, $query);
					}
					
					// Check if a limit for query rows has been set, this means we are in precaching process by JS App client
					if(!$this->limitRows) {
						$this->_db->setQuery ( $query );
					} else {
						$this->_db->setQuery ( $query, $this->limitStart, $this->limitRows);
					}
					try {
						// Security safe check: only SELECT allowed
						if(preg_match('/((?<!`)delete|update|insert|password)/i', $query)) {
							throw new JMapException(sprintf(JText::_('COM_JMAP_QUERY_NOT_ALLOWED_FROM_USER_DATASOURCE' ), $source->name), 'warning');
						}
						$sourceItems = $this->_db->loadObjectList ();
						if ($this->_db->getErrorNum () && !$sourceItems) {
							$queryExplained = null;
							if ($debugMode) {
								$queryExplained = '<br /><br />' . $this->_db->getErrorMsg () . '<br /><br />' .
												  JText::_('COM_JMAP_SQLQUERY_EXPLAINED' ) . '<br /><br />' .
												  $this->_db->getQuery () . '<br /><br />' .
												  JText::_('COM_JMAP_SQLQUERY_EXPLAINED_END' );
							}
							throw new JMapException(sprintf(JText::_('COM_JMAP_ERROR_RETRIEVING_DATA_FROM_USER_DATASOURCE' ), $source->name) . $queryExplained, 'warning');
						}
						// Detected a precaching call, so store in the model state the number of affected rows for JS app
						if($this->limitRows) {
							$this->setState('affected_rows', count($sourceItems));
						}
						
						// Start subQueriesPostProcessor if needed for nested multilevel categories
						if($resultSourceObject->params->get('multilevel_categories', 0) && $this->hasCategorization($resultSourceObject)) {
							// Pre assignment
							$resultSourceObject->data = $sourceItems;
							// Start post processor
							$this->subQueriesPostProcessor($resultSourceObject);
						}
					} catch (JMapException $e) {
						if($e->getErrorLevel() == 'notice' && $debugMode) {
							$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
						} elseif($e->getErrorLevel() != 'notice') {
							$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
						}
						$resultSourceObject->data = array();
						return $resultSourceObject;
					} catch (Exception $e) {
						$jmapException = new JMapException($e->getMessage(), 'warning');
						$this->app->enqueueMessage(sprintf(JText::_('COM_JMAP_ERROR_RETRIEVING_DATA_FROM_USER_DATASOURCE' ), $source->name), 'warning');
						if($debugMode) {
							$this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel());
						}
						$resultSourceObject->data = array();
						return $resultSourceObject;
					}
				}
				break;
				
			case 'menu':
				$menuAccess = null;
				$originalSourceItems = array();
				$autoExcludeNoIndex = null;
				// Unpublished items
				$doUnpublishedItems = $resultSourceObject->params->get('dounpublished', 0);
				// Exclusion menu
				$subQueryExclusion = null;
				$exclusionMenuItems = $resultSourceObject->params->get('exclusion', array());
				if($exclusionMenuItems && !is_array($exclusionMenuItems)) {
					$exclusionMenuItems = array($exclusionMenuItems);
				}
				if(count($exclusionMenuItems) && !in_array('0',$exclusionMenuItems)) {
					$subQueryExclusion = "\n AND menuitems.id NOT IN (" . implode(',', $exclusionMenuItems) . ")";
				}
				$queryChunk = null;
				if(!$doUnpublishedItems) {
					$queryChunk = "\n AND menuitems.published = 1";
				}
				
				// Filter by access if ACL option enabled
				if($disableAcl !== 'disabled') {
					$menuAccess = "\n AND menuitems.access IN ( " . implode(',', $accessLevels) . " )";
				}
				
				// Filter by language only if multilanguage is correctly enabled by Joomla! plugin
				$menuLanguageFilter = null;
				if(JMapLanguageMultilang::isEnabled()) {
					$menuLanguageFilter = "\n AND ( menuitems.language = " . $this->_db->quote('*') . " OR menuitems.language = " . $this->_db->quote($this->langTag) . " ) ";
				}
				
				// Auto exclude noindex articles from XML sitemaps
				$format = $this->getState('format');
				if($format != 'html' && $this->cparams->get('auto_exclude_noindex', 0)) {
					$autoExcludeNoIndex = "\n AND (menuitems.params NOT REGEXP 'noindex')";
				}
				
				$menuQueryItems = "SELECT menuitems.*, menuitems.parent_id AS parent, menuitems.level AS sublevel, menuitems.title AS name, menupriorities.priority" .
								  "\n FROM #__menu as menuitems" .
								  "\n INNER JOIN #__menu_types AS menutypes" .
								  "\n ON menuitems.menutype = menutypes.menutype" .
								  "\n LEFT JOIN #__jmap_menu_priorities AS menupriorities" .
								  "\n ON menupriorities.id = menuitems.id" .
								  "\n WHERE	menuitems.client_id = 0 AND menuitems.published >= 0" . $queryChunk .
								  $menuAccess .
								  $autoExcludeNoIndex .
								  "\n AND menutypes.title = " . $this->_db->quote($source->name) .
								  $menuLanguageFilter .
								  $subQueryExclusion .
								  "\n ORDER BY menuitems.menutype, menuitems.parent_id, menuitems.level, menuitems.lft";
				// Check if a limit for query rows has been set, this means we are in precaching process by JS App client
				if(!$this->limitRows) {
					$this->_db->setQuery ( $menuQueryItems );
				} else {
					$this->_db->setQuery ( $menuQueryItems, $this->limitStart, $this->limitRows);
				}
				try {
					$originalSourceItems = $this->_db->loadObjectList();
					if ($this->_db->getErrorNum ()) {
						throw new JMapException(sprintf(JText::_('COM_JMAP_ERROR_RETRIEVING_DATA' ), $source->name), 'notice');
					}
					// Detected a precaching call, so store in the model state the number of affected rows for JS app
					if($this->limitRows) {
						$this->setState('affected_rows', count($originalSourceItems));
					}
					// Recursive ordering for menu rows ONLY if HTML format, otherwise make no sense so save resources and time
					if($this->documentFormat == 'html') {
						$sourceItems = $this->sortMenu ( $originalSourceItems, $resultSourceObject->params);
					} else {
						$sourceItems = $originalSourceItems;
					}
				} catch (JMapException $e) {
					$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
					$resultSourceObject->data = array();
					return $resultSourceObject;
				} catch (Exception $e) {
					$jmapException = new JMapException($e->getMessage(), 'error');
					$this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel());
					$resultSourceObject->data = array();
					return $resultSourceObject;
				}
				break;
				
			case 'content':
				$access = null;
				$catAccess = null;
				$limitRecent = null;
				$limitFeatured = null;
				$autoExcludeNoIndex = null;
				$dynamicSelectFields = null;
				$dynamicOrdering = null;
				$categoriesJoin = 'RIGHT';
				$defaultOrdering = 'c.ordering';
				$usersTableJoin = null;
				$exclusionWay =  $resultSourceObject->params->get('choose_exclusion_way', 'exclude');
				$exclusionWayOperator = $exclusionWay == 'exclude' ? 'NOT' : '';
				$now = gmdate('Y-m-d H:i:s', time());
				// Exclusion access for Google News Sitemap and if ACL is disabled
				$format = $this->getState('format');

				// Set select fields only if html sitemap format is detected, save memory if XML and not needed
				if($format == 'html') {
					$dynamicSelectFields = 'c.title AS title, cat.title AS category, cat.level,';
				}
				
				// Set select fields only if RSS sitemap format is detected, save memory if not needed
				if($format == 'rss' || $format == 'gnews') {
					$dynamicSelectFields = 'c.title AS title, cat.title AS category,';
				}
				
				// Check if article images are required to be added to the RSS feed text desc
				if($format == 'rss' && (int)$this->cparams->get('rss_include_images', 0)) {
					$dynamicSelectFields .= 'c.images,';
				}
				
				// Check if article author is required to be added to the RSS feed
				if($format == 'rss' && (int)$this->cparams->get('rss_include_author', 0)) {
					$usersTableJoin = "\n LEFT JOIN " . $this->_db->quoteName('#__users') . " AS u ON c.created_by = u.id";
					$dynamicSelectFields .= 'u.name AS authorname, u.email AS authoremail,';
				}
				
				// Manage content articles order
				if($format != 'html' && (int)$resultSourceObject->params->get('orderbydate', 0) == 1) {
					$dynamicOrdering = "created DESC,";
				}
				
				// Manage content articles order
				if($format != 'rss' && $format != 'html' && (int)$resultSourceObject->params->get('orderbydate', 0) == 2) {
					$dynamicOrdering = "modified DESC,";
				}
				
				// Manage content articles order
				if($format != 'html' && (int)$resultSourceObject->params->get('orderbydate', 0) == 3) {
					$dynamicOrdering = "publish_up DESC,";
				}
				
				// Fallback for rss feed always created desc
				if($format == 'rss' && !$dynamicOrdering) {
					$dynamicOrdering = "created DESC,";
				}
				
				// Manage content articles order for the HTML sitemap format
				if($format == 'html' && $resultSourceObject->params->get('orderbyalpha', 0)) {
					$defaultOrdering = "c.title ASC";
				}
				
				if($format != 'gnews' && $disableAcl !== 'disabled') {
					$access = "\n AND c.access IN ( " . implode(',', $accessLevels) . " )";
					$catAccess = "\n AND cat.access IN ( " . implode(',', $accessLevels) . " )";
				}
				
				// Choose to limit valid articles for Google News Sitemap to last n most recent days
				if($format == 'gnews' && $this->cparams->get('gnews_limit_recent', false)) {
					$validDays = $this->cparams->get('gnews_limit_valid_days', 2);
					$limitRecent = "\n AND UNIX_TIMESTAMP(c.publish_up) > " . (time() - (24 * 60 * 60 * $validDays));
				}
				
				// Choose to limit valid articles for the RSS feed to last n most recent days
				if($format == 'rss' && (int)$this->cparams->get('rss_limit_valid_days', null)) {
					$validDays = (int)$this->cparams->get('rss_limit_valid_days');
					$limitRecent = "\n AND UNIX_TIMESTAMP(c.publish_up) > " . (time() - (24 * 60 * 60 * $validDays));
				}
				
				// Choose to filter only by featured articles
				if((int)$resultSourceObject->params->get('limit_featured_articles', 0)) {
					$limitFeatured = "\n AND c.featured = 1";
				}
				
				// Exclusion categories
				$subQueryCatExclusion = null;
				$subQueryCategoryExclusion = null;
				$exclusionCategories = $resultSourceObject->params->get('catexclusion', array());
				// Normalize select options
				if($exclusionCategories && !is_array($exclusionCategories)) {
					$exclusionCategories = array($exclusionCategories);
				}
				
				// Exclusion children categories da table orm nested set model
				if(count($exclusionCategories)) {
					JTable::addIncludePath(JPATH_LIBRARIES . '/joomla/database/table');
					$categoriesTableNested = JTable::getInstance('Category'); 
					$children = array();
					foreach ($exclusionCategories as $topCatID) {
						// Load Children categories se presenti
						$categoriesTableNested->load($topCatID);
						$tempChildren = $categoriesTableNested->getTree();
						if(is_array($tempChildren) && count($tempChildren)) {
							foreach ($tempChildren as $child) {
								if(!in_array($child->id, $children) && !in_array($child->id, $exclusionCategories)) {
									$exclusionCategories[] = $child->id;
								}
							} 
						}
					}
					 
					$subQueryCatExclusion = "\n AND c.catid $exclusionWayOperator IN (" . implode(',', $exclusionCategories) . ")";
					$subQueryCategoryExclusion = "\n AND cat.id $exclusionWayOperator IN (" . implode(',', $exclusionCategories) . ")";
				}
				
				// Exclusion articles
				$subQueryArticleExclusion = null;
				$exclusionArticles = $resultSourceObject->params->get('articleexclusion', array());
				// Normalize select options
				if($exclusionArticles && !is_array($exclusionArticles)) {
					$exclusionArticles = array($exclusionArticles);
				}
				if(count($exclusionArticles)) {
					$subQueryArticleExclusion = "\n AND c.id $exclusionWayOperator IN (" . implode(',', $exclusionArticles) . ")";
				}
				
				// Evaluate content levels to include
				$includeArchived = $this->cparams->get('include_archived', 0);
				$contentLevel = $includeArchived ? ' > 0' : ' = 1';
				
				// Filter by language only if multilanguage is correctly enabled by Joomla! plugin
				$contentLanguageFilter = null;
				$categoryLanguageFilter = null;
				if(JMapLanguageMultilang::isEnabled()) {
					$contentLanguageFilter = "\n AND ( c.language = " . $this->_db->quote('*') . " OR c.language = " . $this->_db->quote($this->langTag) . " ) ";
					$categoryLanguageFilter = "\n AND ( cat.language = " . $this->_db->quote('*') . " OR cat.language = " . $this->_db->quote($this->langTag) . " ) ";
				}
				
				// Check if pagebreaks analysis is required
				$pageBreaksFullText = null;
				if($pageBreaksLinks = $this->cparams->get('show_pagebreaks', 0)) {
					$pageBreaksFullText = "\n ,CONCAT(c.introtext, c.fulltext) AS completetext";
				}
				
				// Check if limit by recent months is set for content data source
				// Manage for latest months placeholder if found one
				$limitLatestItems = null;
				if($monthsLimit = $resultSourceObject->params->get('created_date', null)) {
					$minValidCreatedDate = gmdate ( "Y-m-d H:i:s", strtotime ( "-" . $monthsLimit . " months", time()));
					$limitLatestItems = "\n AND c.created > " . $this->_db->quote($minValidCreatedDate);
					// If we are on a precaching process plus a limit by recent month avoid empty records because of the RIGHT JOIN #__categories
					if($this->limitRows) {
						$categoriesJoin = 'LEFT';
					}
				}

				// Auto exclude noindex articles from XML sitemaps
				if($format != 'html' && $this->cparams->get('auto_exclude_noindex', 0)) {
					$autoExcludeNoIndex = "\n AND (c.metadata NOT REGEXP 'noindex')";
				}
				
				$contentQueryItems = "SELECT c.id, c.alias, c.language, c.publish_up, c.access, c.metakey, catspriorities.priority," .
									 $dynamicSelectFields .
									 "\n cat.id AS catid," .
									 "\n UNIX_TIMESTAMP(c.modified) AS modified," .
									 "\n c.catid AS catslug" .
									 $pageBreaksFullText .
									 "\n FROM " . $this->_db->quoteName('#__content') . " AS c" .
									 "\n LEFT JOIN #__jmap_cats_priorities AS catspriorities ON catspriorities.id = c.catid" .
									 $usersTableJoin .
									 "\n $categoriesJoin JOIN #__categories AS cat ON cat.id = c.catid" .
									 "\n AND c.state $contentLevel".
									 "\n AND ( c.publish_up = " . $this->_db->quote($this->_db->getNullDate()) . " OR c.publish_up <= '$now' )" .
									 "\n AND ( c.publish_down = " . $this->_db->quote($this->_db->getNullDate()) . " OR c.publish_down >= '$now' )" .
									 $limitRecent .
									 $limitFeatured .
									 $limitLatestItems .
									 $access .
									 $contentLanguageFilter .
									 $subQueryCatExclusion .
									 $subQueryArticleExclusion .
									 $autoExcludeNoIndex .
									 "\n WHERE cat.published = '1'" .
									 $catAccess .
									 "\n AND cat.extension = " . $this->_db->quote('com_content') .
									 $categoryLanguageFilter .
									 $subQueryCategoryExclusion .
									 "\n ORDER BY $dynamicOrdering cat.lft, $defaultOrdering";
				
				// Runtime preprocessing for RSS description field
				if($this->documentFormat === 'rss') {
					$contentQueryItems = $this->runtimeRssPreProcessing('c', $contentQueryItems);
				}

				// Check if a limit for query rows has been set, this means we are in precaching process by JS App client
				if(!$this->limitRows) {
					$this->_db->setQuery ( $contentQueryItems );
				} else {
					$this->_db->setQuery ( $contentQueryItems, $this->limitStart, $this->limitRows);
				}
				try {
					$sourceItems = $this->_db->loadObjectList ();
					if ($this->_db->getErrorNum ()) {
						throw new JMapException(sprintf(JText::_('COM_JMAP_ERROR_RETRIEVING_DATA' ), $source->name), 'notice');
					}
					// Detected a precaching call, so store in the model state the number of affected rows for JS app
					if($this->limitRows) {
						$this->setState('affected_rows', count($sourceItems));
					}
					
					// Sub article pagebreaks processing
					if($pageBreaksLinks) {
						foreach ($sourceItems as $article) {
							$this->addPagebreaks($article);
						}
					}
				} catch (JMapException $e) {
					$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
					$resultSourceObject->data = array();
					return $resultSourceObject;
				} catch (Exception $e) {
					$jmapException = new JMapException($e->getMessage(), 'error');
					$this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel());
					$resultSourceObject->data = array();
					return $resultSourceObject;
				}
				break;
				
			case 'plugin':
				// Get the language param for the user data source and ensure that it's all langs or match the current language, if not skip getting data
				$languageTag = JMapLanguageMultilang::getCurrentSefLanguage();
				$dataSourceLanguage = $resultSourceObject->params->get('datasource_language', '*');
				if($dataSourceLanguage != '*' && ($languageTag != $dataSourceLanguage)) {
					// Detected a precaching call, set 0 affected rows to complete correctly the precaching process just now
					if($this->limitRows) {
						$this->setState('affected_rows', 0);
					}
					break;
				}
				
				// Call the plugin interface and retrieve data
				$pluginName = strtolower($source->name);
				$className = 'JMapFilePlugin' . ucfirst($source->name);
				try {
					// Check if the plugin interface implementation exists
					if(!file_exists(JPATH_COMPONENT_ADMINISTRATOR . '/plugins/' . $pluginName . '/' . $pluginName . '.php')) {
						throw new JMapException(sprintf(JText::_('COM_JMAP_ERROR_PLUGIN_DATASOURCE_NOT_EXISTS' ), $pluginName . '.php'), 'warning');
					}
					// Include for multiple instances of this data source
					include_once JPATH_COMPONENT_ADMINISTRATOR . '/plugins/' . $pluginName . '/' . $pluginName . '.php';

					// Check if the concrete class exists now
					if(!class_exists($className)) {
						throw new JMapException(sprintf(JText::_('COM_JMAP_ERROR_PLUGIN_CLASS_NOT_EXISTS' ), $className), 'warning');
					}
					
					// Load the language file for the plugin, manage partial language translations
					$jLang = JFactory::getLanguage();
					$jLang->load($pluginName, JPATH_COMPONENT_ADMINISTRATOR . '/plugins/' . $pluginName, 'en-GB', true, true);
					if($jLang->getTag() != 'en-GB') {
						$jLang->load($pluginName, JPATH_COMPONENT_ADMINISTRATOR . '/plugins/' . $pluginName, null, true, false);
					}
					
					// Instantiate the plugin class, inject $this class and manage limitRows for precaching in third party plugins
					$pluginInstance = new $className();
					$retrievedData = $pluginInstance->getSourceData($resultSourceObject->params, $this->_db, $this);

					// 1) first structure required: plain list of items -> PLAIN LIST OF ELEMENTS
					if(!array_key_exists('items', $retrievedData)) {
						throw new JMapException(sprintf(JText::_('COM_JMAP_ERROR_PLUGIN_NODATA_RETURNED' ), $pluginName), 'warning');
					}
					$sourceItems = $retrievedData['items'];

					// Check if additional structures for nested categories tree are returned
					// 2) second structure optional: plain list of items grouped by cats -> LIST OF ELEMENTS GROUPED BY PLAIN CATS STRUCTURE
					if(array_key_exists('items_tree', $retrievedData)) {
						$resultSourceObject->itemsTree = $retrievedData['items_tree'];
					}
					// 3) third structure optional: nested tree of cats by parents -> LIST OF ELEMENTS GROUPED BY NESTED CATS STRUCTURE
					if(array_key_exists('categories_tree', $retrievedData)) {
						$resultSourceObject->categoriesTree = $retrievedData['categories_tree'];
					}
				} catch (JMapException $e) {
					if($e->getErrorLevel() == 'notice' && $debugMode) {
						$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
					} elseif($e->getErrorLevel() != 'notice') {
						$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
					}
					$resultSourceObject->data = array();
					return $resultSourceObject;
				} catch (Exception $e) {
					$debugMode = $this->cparams->get('enable_debug', 0);
					$jmapException = new JMapException($e->getMessage(), 'warning');
					$this->app->enqueueMessage(sprintf(JText::_('COM_JMAP_ERROR_RETRIEVING_DATA_FROM_USER_DATASOURCE' ), $source->name), 'warning');
					if($debugMode) {
						$this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel());
					}
					$resultSourceObject->data = array();
					return $resultSourceObject;
				}
				break;
				
			case 'links':
				// Re-initialize the $sourceItems var as an object not an array
				$sourceItems = new stdClass();
				$sourceItems->title = array();
				$sourceItems->link = array();
				
				// Get the language param for the links data source and ensure that it's all langs or match the current language, if not skip getting data
				$languageTag = JMapLanguageMultilang::getCurrentSefLanguage();
				$dataSourceLanguage = $resultSourceObject->params->get('datasource_language', '*');
				if($dataSourceLanguage != '*' && ($languageTag != $dataSourceLanguage)) {
					// Detected a precaching call, set 0 affected rows to complete correctly the precaching process just now
					if($this->limitRows) {
						$this->setState('affected_rows', 0);
					}
					break;
				}
				
				// Check if a limit for query rows has been set, this means we are in precaching process by JS App client
				if(!$this->limitRows) {
					// Get directly the links from the source
					$sourceItems = $resultSourceObject->chunks;
				} else {
					// Get directly the links from the source
					$sourceItems->title = array_slice($resultSourceObject->chunks->title, $this->limitStart, $this->limitRows, false);
					$sourceItems->link = array_slice($resultSourceObject->chunks->link, $this->limitStart, $this->limitRows, false);
					
					// Detected a precaching call, so store in the model state the number of affected rows for JS app
					$this->setState('affected_rows', count($sourceItems->link));
				}
			
				break;
		}
		 
		// Final assignment
		$resultSourceObject->data = $sourceItems;
	 
		return $resultSourceObject;
	}
	
	/**
	 * Get available sitemap source
	 * @access private
	 * @return array
	 */
	private function getSources() {
		$join = null;
		$where = array();
		
		// Check exclude from menu view params data sources IDs
		$filterDataSource = $this->getState('cparams')->get('datasource_filter', array());
		// Only if first array item is not the 'No filter' false first option of multiselect
		if(!empty($filterDataSource) && $filterDataSource[0]) {
			$where[] = "\n v.id IN (" . implode(',', $filterDataSource) . ")";
		}
		
		// Check if JS client app has set some data source restrictions
		if($dataSourceID = $this->getState('datasourceid', null)) {
			$where[] = "\n v.id = " . $this->_db->quote($dataSourceID);
		}
		
		// Check if some restrictions based on dataset filter are found
		$filterDataset = $this->app->input->getInt('dataset', null);
		if(!empty($filterDataset)) {
			$join = "\n INNER JOIN #__jmap_dss_relations AS dss" .
					"\n ON v.id = dss.datasourceid";
			$where[] = "\n dss.datasetid = " . (int)$filterDataset;
		}
		
		// Default for published data sources
		$where[] = "\n v.published = 1";
		
		$query = "SELECT v.*" .
				 "\n FROM #__jmap AS v" .
				 $join .
				 "\n WHERE " . implode(' AND ', $where) .
				 "\n ORDER BY v.ordering ASC";
		$this->_db->setQuery ( $query );
		
		$this->sources = $this->_db->loadObjectList ();
		
		return $this->sources;
	}
	
	/**
	 * Load manifest file for this type of data source
	 * @access private
	 * @return mixed
	 */
	private function loadManifest($option) {
		// Load configuration manifest file
		$fileName = JPATH_COMPONENT . '/manifests/' . $option . '.json';
		
		// Check if file exists and is valid manifest
		if(!file_exists($fileName)) {
			return false;
		}
		
		// Load the manifest serialized file and assign to local variable
		$manifest = file_get_contents($fileName);
		$manifestConfiguration = json_decode($manifest);
		
		return $manifestConfiguration;
	}
	
	/**
	 * Load manifest file for this type of data source
	 * @access private
	 * @return mixed
	 */
	private function loadRouteManifest($option) {
		// Load configuration manifest file
		$fileName = JPATH_COMPONENT_ADMINISTRATOR . '/framework/route/manifests/' . $option . '.json';
	
		// Check if file exists and is valid manifest
		if(!file_exists($fileName)) {
			return false;
		}
	
		// Load the manifest serialized file and assign to local variable
		$manifest = file_get_contents($fileName);
		$manifestConfiguration = json_decode($manifest);
	
		return $manifestConfiguration;
	}
	
	/**
	 * Detect if a data source has ideally a categorization active, through title categorization param set and not empty
	 * 
	 * @access private
	 * @param Object $dataSource
	 * @param boolean $ignoreFormat
	 * @return boolean
	 */
	private function hasCategorization($dataSource, $ignoreFormat = false) {
		// Check first of all for right focument format, used only for presentation purpouse for HTML document format
		if(!is_null($this->documentFormat) && $ignoreFormat === false) {
			if($this->documentFormat != 'html') {
				return false;
			}
		}
		
		// Check if data source is elated to categories entities itself
		if(preg_match('/categor|cats|catg/i', $dataSource->chunks->table_maintable)) {
			return true;
		}
		
		// Check if a valid field has been chosen and activated for category titles
		if(isset($dataSource->chunks->use_category_title_jointable1) && $dataSource->chunks->use_category_title_jointable1) {
			return true;
		}
		if(isset($dataSource->chunks->use_category_title_jointable2) && $dataSource->chunks->use_category_title_jointable2) {
			return true;
		}
		if(isset($dataSource->chunks->use_category_title_jointable3) && $dataSource->chunks->use_category_title_jointable3) {
			return true;
		}
		
		return false;
	}
	
	/**
	 * Fetch default table fields used to filter out categories query
	 *
	 * @access protected
	 * @param string $tableName
	 * @return array 
	 */
	protected function fetchAutoInjectDefaultWhereFields($tableName, $manifestConfig, $source) {
		$whereConditions = array();
		$excludeConditions = isset($manifestConfig->category_exclude_condition) ? $manifestConfig->category_exclude_condition : array();
		// Get required maintable table fields, if not valid throw exception
		$columnsQuery = "SHOW COLUMNS FROM " . $this->_db->quoteName($tableName);
		$this->_db->setQuery($columnsQuery);
		try {
			if($tableFields = $this->_db->loadColumn()) {
				// *AUTO WHERE PART* injected fields
				if(is_array($tableFields) && count($tableFields)) {
					// Published field supported
					if(in_array('published', $tableFields) && !(in_array('published', $excludeConditions))) {
						$whereConditions[] = $this->_db->quoteName($tableName) . "." . $this->_db->quoteName('published') . " = " . $this->_db->quote(1);
					} elseif(in_array('state', $tableFields) && !(in_array('state', $excludeConditions))) { // State field supported fallback
						$whereConditions[] = $this->_db->quoteName($tableName) . "." . $this->_db->quoteName('state') . " = " . $this->_db->quote(1);
					}
						
					// Access field supported
					if(in_array('access', $tableFields) && !(in_array('access', $excludeConditions))) {
						if(!$this->accessLevel) {
							// Load access level if not loaded
							$user = JFactory::getUser();
							$this->accessLevel = $user->getAuthorisedViewLevels();
						}
						$whereConditions[] = $this->_db->quoteName($tableName) . "." . $this->_db->quoteName('access') . " IN (" . implode(',', $this->accessLevel) . ")";
					}
				
					// Language field supported
					if(in_array('language', $tableFields) && !(in_array('language', $excludeConditions))) {
						$whereConditions[] =  " (" . $this->_db->quoteName($tableName) . "." . $this->_db->quoteName('language') . " = " . $this->_db->quote('*') .
											  " OR " . $this->_db->quoteName($tableName) . "." . $this->_db->quoteName('language') . " = " . $this->_db->quote('') .
											  " OR " . $this->_db->quoteName($tableName) . "." . $this->_db->quoteName('language')  . " = " . $this->_db->quote($this->langTag) . ")";
					}
					
					// Explicit category conditions from manifest config file
					if(isset($manifestConfig->category_condition) && is_array($manifestConfig->category_condition)) {
						foreach ($manifestConfig->category_condition as $condition) {
							if(!empty($source->chunks->where1_maintable) && !empty($source->chunks->where1_value_maintable) && strpos($condition, '$$$')) {
								if(strpos($source->chunks->where1_value_maintable, ',')) {
									$condition = str_replace('@', ' IN(', $condition);
									$condition = str_replace('$$$', $source->chunks->where1_value_maintable . ')', $condition);
								} else {
									$condition = str_replace('@', '=', $condition);
									$condition = str_replace('$$$', $source->chunks->where1_value_maintable, $condition);
								}
							} elseif(strpos($condition, '$$$')) {
								$condition = null;
							}
							
							// Assignment if valid $condition
							if($condition) {
								$whereConditions[] = $condition;
							}
						}
					}
				}
			}
		} catch (Exception $e) {
			return false;
		}
		
		return $whereConditions;
		
	}
	
	/**
	 * 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;
		$additionalCategoriesSorting = 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);
				}

				if(isset($manifestConfiguration->additional_categories_sorting)) {
					$additionalCategoriesSorting = "\n ORDER BY " . $manifestConfiguration->additional_categories_sorting;
				}
				
				// 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 .
				$additionalCategoriesSorting;
		$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);
	}
	  
	/**
	 * Get the Data
	 * @access public
	 * @return array
	 */
	public function getSitemapData() {
		// Get the view
		$this->sources = $this->getSources ();
		$data = array ();
		$user = JFactory::getUser();
		// Getting degli access levels associati all'utente in base ai gruppi di appartenenza
		$this->accessLevel = $user->getAuthorisedViewLevels();
		// Get data for a view
		foreach ( $this->sources as $source ) {
			$sourceData = $this->getSourceData ( $source, $this->accessLevel );
			// Data retrieved for this data source, assign safely
			if($sourceData && !empty($sourceData->data)) {
				$data[] = $sourceData;
			}
		}
		$this->data = $data;
		
		return $data;
	}
	
	/**
	 * Get excluded links from the sitemap
	 * @access public
	 * @param string $liveSite to replace
	 * @return array
	 */
	public function getExcludedLinks($liveSite) {
		// Exclude filtering if the client is the backend metainfo that manages all
		if($this->state->get('metainfojsclient', false)) {
			return array();
		}
		
		$query = "SELECT REPLACE(" . $this->_db->quoteName('linkurl') . ", '" . $liveSite . "', '') AS " . $this->_db->quoteName('linkurl') . " ," .
				 "\n " . $this->_db->quoteName('excluded') .
				 "\n FROM #__jmap_metainfo" .
				 "\n WHERE " . $this->_db->quoteName('excluded') . " = 1" ;
		$this->_db->setQuery ( $query );
		
		$excludedLinks = $this->_db->loadAssocList ('linkurl', 'excluded');
		
		return $excludedLinks;
	}
	
	/**
	 * Get the component params width view override/merge
	 * @access public
	 * @return Object
	 */
	public function getComponentParams() {
		if(is_object($this->cparams)) {
			return $this->cparams;
		}

		$this->cparams = $this->app->getParams('com_jmap');
		return $this->cparams;
	}
	
	/**
	 * Export XML file for sitemap
	 *
	 * @access public
	 * @param string $contents
	 * @param string $fileNameSuffix
	 * @param string $fileNameFormat
	 * @param string $fileNameLanguage
	 * @param string $fileNameDatasetFilter
	 * @param string $fileNameItemidFilter
	 * @param string $mimeType
	 * @param boolean $isFile
	 * @return boolean
	 */
	public function exportXMLSitemap($contents, $fileNameSuffix, $fileNameFormat, $fileNameLanguage, $fileNameDatasetFilter, $fileNameItemidFilter, $mimeType, $isFile = false) {
		$this->sendAsBinary($contents, 'sitemap_' . $fileNameSuffix . $fileNameLanguage . $fileNameDatasetFilter . $fileNameItemidFilter . '.' . $fileNameFormat, $mimeType, $isFile);
	
		return false;
	}
	 
	/**
	 * Class Constructor
	 * @access public
	 * @return Object&
	 */
	function __construct($config = array()) {
		parent::__construct ($config);
		$this->cparams = $this->app->getParams('com_jmap');
		// Check if a module request is detected, in this case merge module params instead of menu view params: Component -> module specific level params override
		if(isset($config['jmap_module']) && $config['jmap_module']) {
			$query = $this->_db->getQuery(true);
			$query->select('params');
			$query->from('#__modules');
			$query->where($this->_db->quoteName('id') . ' = ' . (int)$config['jmap_module']);
			$strParams = $this->_db->setQuery($query)->loadResult();
			$moduleParams = new JRegistry;
			$moduleParams->loadString($strParams);
			// Merge module params in place of view params simulating
			$this->cparams->merge($moduleParams);
			// Ensure all links will open up the parent main window
			$this->cparams->set('opentarget', '_parent');
		}
		
		$this->setState('cparams', $this->cparams);
		$this->documentFormat = $config['document_format'];
		$this->setState('documentformat', $this->documentFormat);
		
		// Languages installed on this system
		$langManager = JFactory::getLanguage();
		
		$this->fallbackDefaultLanguage = $langManager->getDefault();
		$this->fallbackDefaultLanguageRFC = str_replace('-', '_', strtolower($this->fallbackDefaultLanguage));
		
		$this->langTag = $langManager->getTag();
		$this->siteLanguageRFC = str_replace('-', '_', strtolower($this->langTag));
		
		// Init supported 3PD extensions tables for Google news sitemap
		$this->supportedGNewsTablesOptions = array('#__k2_items',
												   '#__zoo_item',
												   '#__easyblog_post',
												   '#__mt_links'
		);

		// Calculate limitstart and limitrows if precaching process detected
		if(isset($config['iteration_counter'])) {
			$formatLimitParam = in_array($this->documentFormat, array('images', 'videos')) ? $this->cparams->get('precaching_limit_images', 50) : $this->cparams->get('precaching_limit_xml', 5000);
			$this->limitStart = $config['iteration_counter'] * $formatLimitParam;
			$this->limitRows = $formatLimitParam;
		}
	}
}