<?php
/**
* 2023 Anvanto
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
*
*  @author    Anvanto <anvantoco@gmail.com>
*  @copyright 2023 Anvanto
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*/

class anBlogContentTheme
{
    public function __construct()
    {
        $this->themeDir = Context::getContext()->shop->theme->getDirectory();
        $this->themeName = Context::getContext()->shop->theme->getName();
        
        $this->moduleDir = _PS_MODULE_DIR_ . 'anblog/';

        $this->contentDir = $this->themeDir.'assets/antheme/anblog/';
        $this->jsonContentFile = $this->themeDir.'assets/antheme/anblog/widgets.json';
    }


    public function getContentFilePath()
    { 
        return $this->getContentDir() . 'widgets.json';
    }

    public function getContentDir()
    { 
        $this->createFolders();

        if (Tools::file_exists_no_cache($this->contentDir)){
            return $this->contentDir;
        }

        return $this->moduleDir;
    }

    public function getContentFile()
    { 
        if (Tools::file_exists_no_cache($this->jsonContentFile)){
            return Tools::file_get_contents($this->jsonContentFile);
        }

        return '';
    } 

    public function createFolders()
    {
        $this->checkCreateFolder($this->contentDir);
    }    

    public function checkCreateFolder($path)
    {
        if (!Tools::file_exists_no_cache($path)){
            mkdir($path, 0777, true);
            Tools::copy($this->moduleDir . 'index.php', $path . 'index.php');
        }
    }   





    
 
}