src/web/app/themes/atahualpa/functions/bfa_rotating_header_images.php
author ymh <ymh.work@gmail.com>
Mon, 09 Dec 2019 11:32:04 +0100
changeset 7 81d22971b333
parent 1 407d5a626a50
permissions -rw-r--r--
adding missing wp-config file

<?php
function bfa_rotating_header_images() {
	global $bfa_ata;

	$files = array();
	$img_folder = $bfa_ata['ata_images_dir'];

    if(!isset($bfa_ata['ata_images_dir']) 
    OR ($bfa_ata['ata_images_dir'] == '') ) {	
       	$img_folder = 'ata-images'; } 

    if($bfa_ata['images_root'] != "wp-content") {
           $imgpath = get_template_directory() . '/images/header/';
           $imgdir  = get_template_directory_uri() . '/images/header/';
        } else {
           $imgpath = WP_CONTENT_DIR . '/' . $img_folder . '/header/';
           $imgdir  = content_url() . '/' . $img_folder . '/header/';
        }

		$dh  = @opendir($imgpath);
		if ($dh == FALSE) {
			echo $imgpath . ' - ' . $bfa_ata['images_root'] . '<br /><strong><span style="color: #ff0000;">the folder permission or path to your header image folder is incorrect </color></span><br />';
			return(FALSE);
		}
		while (FALSE !== ($filename = readdir($dh))) {
			if( preg_match('/\.jpg/i', $filename) || preg_match('/\.gif/i', $filename) || preg_match('/\.png/i', $filename) ) {
		   $files[] = $filename;
		   }
		}

		if(isset($bfa_ata['header_image_sort_or_shuffle'])) {
			if ($bfa_ata['header_image_sort_or_shuffle'] == "Sort") {
				sort($files); } 
			else { 
				shuffle($files); }
		}
		
		closedir($dh);

		foreach($files as $value) {
			$bfa_header_images[] = '\'' . $imgdir . $value . '\'';
		} 

return $bfa_header_images;
}
?>