<?php
/**
 * Created by ra.
 * Date: 7/19/2016
 */

class td_analyze_css_util {
	//generate unique_ids
	private static $unique_id_counter = 0;

	static function td_generate_unique_id() {
		self::$unique_id_counter++;
		return 'td_live_css_uid_' . self::$unique_id_counter . '_' . uniqid();
	}

	static function td_check_cache_dir( $dir ) {
	    if ( ! file_exists( $dir ) ) {
	        @mkdir( $dir, 0775, true );
	        if ( ! file_exists( $dir ) ) {
	            return false;
	        }
	    }

	    if ( ! is_writable( $dir ) ) {
	        return false;
	    }

	    $index_file = rtrim( $dir, '/\\' ) . '/index.html';
	    if ( ! is_file( $index_file ) ) {
	        @file_put_contents( $index_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by TagDiv Css Analyzer</body></html>' );
	    }

	    return true;
	}
}
