1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-14 09:04:38 +02:00

Add Monstra from HG Commit 683dcb70c4cc

This commit is contained in:
Awilum
2012-09-25 19:09:50 +03:00
parent d2db42b2bb
commit 4a5fea5f5b
251 changed files with 35026 additions and 0 deletions

View File

@@ -0,0 +1,195 @@
<?php
/**
* Themes plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Themes', 'themes'),
__('Themes manager', 'themes'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
// Include Admin
Plugin::admin('themes', 'box');
}
class Themes {
/**
* Get Themes
*/
public static function getAdminThemes() {
$themes_folders = array();
// Get all themes folders
$_themes_admin_folders = Dir::scan(THEMES_ADMIN);
// Create an array of valid themes folders
foreach($_themes_admin_folders as $folder) if (File::exists(THEMES_ADMIN . DS . $folder . DS . 'index.template.php')) $__themes_admin_folders[] = $folder;
foreach($__themes_admin_folders as $theme) $themes[$theme] = $theme;
return $themes;
}
/**
* Get Admin Themes
*/
public static function getSiteThemes() {
$themes_folders = array();
// Get all themes folders
$_themes_folders = Dir::scan(THEMES_SITE);
// Create an array of valid themes folders
foreach($_themes_folders as $folder) if (File::exists(THEMES_SITE . DS . $folder . DS . 'index.template.php')) $__themes_folders[] = $folder;
foreach($__themes_folders as $theme) $themes[$theme] = $theme;
return $themes;
}
/**
* Get Templates
*
* @param string $theme Theme name
* @return array
*/
public static function getTemplates($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$templates = array();
// Get all templates in current theme folder
$templates = File::scan(THEMES_SITE . DS . $theme, '.template.php');
return $templates;
}
/**
* Get Chunks
*
* @param string $theme Theme name
* @return array
*/
public static function getChunks($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$chunks = array();
// Get all templates in current theme folder
$chunks = File::scan(THEMES_SITE . DS . $theme, '.chunk.php');
return $chunks;
}
/**
* Get Styles
*
* @param string $theme Theme name
* @return array
*/
public static function getStyles($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$styles = array();
// Get all templates in current theme folder
$styles = File::scan(THEMES_SITE . DS . $theme . DS . 'css', '.css');
return $styles;
}
/**
* Get Scripts
*
* @param string $theme Theme name
* @return array
*/
public static function getScripts($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$scripts = array();
// Get all templates in current theme folder
$scripts = File::scan(THEMES_SITE . DS . $theme . DS . 'js', '.js');
return $scripts;
}
}
/**
* Chunk frontend class
*/
class Chunk {
/**
* Get chunk
*
* @param string $name Chunk name
* @param string $theme Theme name
*/
public static function get($name, $theme = null) {
$name = (string) $name;
$current_theme = ($theme === null) ? null : (string) $theme;
if ($current_theme == null) $current_theme = Option::get('theme_site_name');
$chunk_path = THEMES_SITE . DS . $current_theme . DS;
// Is chunk exist ?
if (file_exists($chunk_path . $name . '.chunk.php')) {
// Is chunk minified
if ( ! file_exists(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php') or
filemtime(THEMES_SITE . DS . $current_theme . DS . $name .'.chunk.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php')) {
$buffer = file_get_contents(THEMES_SITE. DS . $current_theme . DS . $name .'.chunk.php');
$buffer = Minify::html($buffer);
file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php', $buffer);
}
// Include chunk
include MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php';
}
}
}