# hurrytimer/2.6.2/includes/CSS_Builder.php

HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress &amp; WooCommerce, version 2.6.2. 85 lines.

- Page: https://pluginprobe.com/plugins/hurrytimer/2.6.2/code/includes/CSS_Builder.php
- Raw: https://pluginprobe.com/plugins/hurrytimer/2.6.2/raw/includes/CSS_Builder.php
- Modified: 2021-04-13T09:36:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/hurrytimer/2.6.2/code/includes/CSS_Builder.php#L10-L20`.

```php
<?php

namespace Hurrytimer;

use Hurrytimer\Traits\Singleton;

class CSS_Builder
{
    use Singleton;

    public function get_build_url()
    {
        $hash = $this->get_current_build_hash();

        $file = $this->get_build_path( $hash );

        if ( !file_exists( $file ) ) {
            $hash = $this->build();
        }

        $upload_dir = wp_get_upload_dir();

        return set_url_scheme( trailingslashit( $upload_dir[ 'baseurl' ] ) . $this->get_build_relative_path( $hash ) );
    }

    private function get_current_build_hash()
    {
        return get_option( 'hurrytimer_css_build_hash' );
    }

    public function delete_build( $hash )
    {
        $file = $this->get_build_path( $hash );

        @unlink( $file );
    }

    /**
     * Re/Build CSS file
     */
    public function build()
    {
        ob_start();
        include HURRYT_DIR . 'assets/css/main.css';
        include __DIR__ . '/css_template.php';

        $css = ob_get_clean();

        $this->delete_build( $this->get_current_build_hash() );

        $hash = substr( md5( time() ), 0, 16 );

        $file = $this->get_build_path( $hash );
        
        file_put_contents( $file, $css );

        update_option( 'hurrytimer_css_build_hash', $hash );

        return $hash;
    }

    private function get_build_relative_path( $hash )
    {
        $uploads_dir = wp_get_upload_dir();

        $relative_dir = implode( DIRECTORY_SEPARATOR, [ 'hurrytimer', 'css' ] );

        $path = trailingslashit( $uploads_dir[ 'basedir' ] ) . $relative_dir;

        if ( !file_exists( $path ) ) {
            mkdir( $path, 0777, true );
        }

        return apply_filters( 'hurryt_css_path', trailingslashit( $relative_dir ) . $hash . '.css' );
    }

    public function get_build_path( $hash )
    {
        $upload_dir = wp_get_upload_dir();

        return trailingslashit( $upload_dir[ 'basedir' ] ) . $this->get_build_relative_path( $hash );

    }

}
```
