<?php
/**
 * @author QuanticaLabs - http://codecanyon.net/user/QuanticaLabs/portfolio?ref=QuanticaLabs
 *
 * @link			http://codecanyon.net/item/timetable-responsive-schedule-for-joomla/9749539?ref=QuanticaLabs
 * @copyright		Copyright (C) 2008 - 2014 quanticalabs.com . All rights reserved.
 * @license			GNU General Public License version 2 or later; see LICENSE under Licensing/ directory
 */
 
defined('_JEXEC') or die('Restricted access');

class  TimetableUtils {
	
	public static function getGoogleFonts() {
		$google_fonts_file = COM_TIMETABLE_PATH . "/googlefont/font.txt";
		$fontsArray = json_decode(file_get_contents($google_fonts_file));
		if($fontsArray===NULL || (time()-$fontsArray->last_update>2*7*24*60*60))
		{
			$google_api_url = 'http://quanticalabs.com/.tools/GoogleFont/font.txt';			
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($ch, CURLOPT_HEADER, false);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
			curl_setopt($ch, CURLOPT_URL, $google_api_url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
			$fontsArray = json_decode(curl_exec($ch));
			$fontsArray->last_update = time();
			file_put_contents($google_fonts_file, json_encode($fontsArray));
		}
		return $fontsArray;
	}
}