<?php
/* version: 20181031 */
// Usage example: O__blogPreviewList(4,0,"d") OR echo (O__blogPreviewList(4,0,"d"));

function O__blogsList($O__PT,$O__blogCount,$O__blogSortKey,$O__blogSortDirection){
	global $O__DBpath;

	// Load settings
	$O__fileData = O__XMLdata($O__DBpath . "/pageTypes/" . $O__PT . "/configs/settings.xml", 0, 0);
	$O__dataStoragePath = $O__DBpath . "/pageTypes/" . $O__PT . O__XMLgetData($O__fileData,"/settings/setting[@id='pathData']/value") . "/";
	unset($O__fileData);

	$O__filesArray = O__dirToArray($O__dataStoragePath); // index blog data
	
	if (count($O__filesArray)){ // if there are blogs
		
		$O__blogsArray = array();
		
		// Go through all blogs
		for($i=0;$i<count($O__filesArray);$i++){
			$O__blogName = substr($O__filesArray[$i][0],0,-4);
			$O__fileData = O__XMLdata($O__dataStoragePath . $O__blogName . ".xml", 0, 0);
			$O__published = $O__fileData->published;
			//$O__imgPreview = $O__fileData->imgPreview;
			
			if($O__published == 1){
				
				// Create machine-sortable date
				$O__dateMachine = (string)$O__fileData->date->year;
				if((string)$O__fileData->date->month<10){ $O__dateMachine .= "0"; }
				$O__dateMachine .= (string)$O__fileData->date->month;
				if((string)$O__fileData->date->day<10){ $O__dateMachine .= "0"; }
				$O__dateMachine .= (string)$O__fileData->date->day;
				
				// Create blogs-to-use array
				$O__blogsArray[] = array( 
										$O__dateMachine,
										(string)$O__fileData->date->year,
										(string)$O__fileData->date->month,
										(string)$O__fileData->date->day,
										(string)$O__fileData->title,
										(string)$O__fileData->summary,
										(string)$O__fileData->imgPreview,
										$O__blogName
									);
			}
		
		}
		unset($O__fileData);
				
		$O__blogsArray = O__sortMultiArray($O__blogsArray,$O__blogSortKey,$O__blogSortDirection);
		
		return $O__blogsArray;
		
	}

}

?>
