/** * Load application assets to a public folder * * @param string $from * @param string $to * @param boolean $import * @return Module */ public function loadAssets($from, $to, $import = false) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets') && is_writable($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets')) { $toDir = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to; if (!file_exists($toDir)) { mkdir($toDir); $dir = new Dir($from, ['absolute' => true, 'recursive' => true]); $dir->copyDir($toDir, false); } $cssDirs = ['css', 'styles', 'style']; $jsDirs = ['js', 'scripts', 'script', 'scr']; $cssType = $import ? 'import' : 'link'; foreach ($cssDirs as $cssDir) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $cssDir)) { $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $cssDir); foreach ($dir->getFiles() as $cssFile) { if ($cssFile != 'index.html') { $css = BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $cssDir . '/' . $cssFile; if (!in_array($css, $this->assets['css'][$cssType]) && substr($css, -4) == '.css' && stripos($css, 'public') === false) { $this->assets['css'][$cssType][] = $css; } } } } } foreach ($jsDirs as $jsDir) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $jsDir)) { $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $jsDir); foreach ($dir->getFiles() as $jsFile) { if ($jsFile != 'index.html') { $js = BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $jsDir . '/' . $jsFile; if (!in_array($js, $this->assets['js']) && substr($js, -3) == '.js' && stripos($js, 'public') === false) { $this->assets['js'][] = $js; } } } } } } return $this; }