122 lines
3.5 KiB
PHP
122 lines
3.5 KiB
PHP
<?php
|
|
|
|
defined('_CREDEXEC_') or die();
|
|
|
|
// Inclure l'autoloader de Composer
|
|
require_once _CRED_ABSPATH_ . 'vendor/autoload.php';
|
|
|
|
// Inclure le fichier de configuration
|
|
require_once _CRED_ABSPATH_ . 'app/config.php';
|
|
|
|
class CRED {
|
|
|
|
private static $instance = NULL;
|
|
|
|
protected function __construct() {
|
|
self::import('app.libraries.base');
|
|
}
|
|
|
|
|
|
/**
|
|
* Getting instance. This Class is a singleton class
|
|
* @return \static
|
|
*/
|
|
public static function instance() {
|
|
// Get an instance of Class
|
|
if(!self::$instance) self::$instance = new self();
|
|
|
|
// Return the instance
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Vérifie si le mode debug est activé
|
|
* @return bool
|
|
*/
|
|
public static function isDebugMode() {
|
|
return defined('_CRED_DEBUG_MODE_') && _CRED_DEBUG_MODE_ === true;
|
|
}
|
|
|
|
/**
|
|
* Détermine le chemin du template à utiliser en fonction du mode debug
|
|
* @param string $template_path Chemin du template standard
|
|
* @return string Chemin du template à utiliser
|
|
*/
|
|
public static function getTemplatePath($template_path) {
|
|
if (self::isDebugMode()) {
|
|
// Remplacer le chemin standard par le chemin newSteps
|
|
$new_path = str_replace(_CRED_TEMPLATES_PATH_, _CRED_NEW_TEMPLATES_PATH_, $template_path);
|
|
|
|
// Vérifier si le fichier existe dans newSteps
|
|
if (file_exists(_CRED_ABSPATH_ . $new_path)) {
|
|
return $new_path;
|
|
}
|
|
}
|
|
|
|
return $template_path;
|
|
}
|
|
|
|
public static function getInstance($file, $namespace="", $class_name = NULL) {
|
|
/** Import the file using import method **/
|
|
$override = self::import($file);
|
|
|
|
/** Generate class name if not provided **/
|
|
if($class_name === null || !trim($class_name))
|
|
{
|
|
$ex = explode('.', $file);
|
|
$file_name = end($ex);
|
|
if(!empty($namespace))
|
|
$class_name = '\\'.$namespace.'\CRED_'.$file_name;
|
|
else
|
|
$class_name = 'CRED_'.$file_name;
|
|
}
|
|
|
|
// If overrode class exists then return the it instead of original class
|
|
if($override) $class_name .= '_override';
|
|
|
|
/** Generate the object **/
|
|
if(class_exists($class_name)) {
|
|
|
|
return new $class_name();
|
|
|
|
/* if($class_name::$instance === null) {
|
|
echo $class_name;
|
|
return new $class_name();
|
|
} else {
|
|
return self::$instance;
|
|
} */
|
|
} else {
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function import($file, $return_path = false) {
|
|
|
|
$original_exploded = explode('.', $file);
|
|
$file = implode(DS, $original_exploded) . '.php';
|
|
|
|
$path = _CRED_ABSPATH_ . $file;
|
|
|
|
// Return the file path without importing it
|
|
if($return_path) return $path;
|
|
|
|
if(file_exists($path)) require_once $path;
|
|
}
|
|
|
|
public function init() {
|
|
$factory = self::getInstance('app.libraries.factory');
|
|
$factory->load_actions();
|
|
$factory->load_filters();
|
|
|
|
// Charger le système de rappel de crédit
|
|
self::import('app.models.credit');
|
|
/* self::import('app.libraries.credit-reminder'); */
|
|
|
|
// Charger les shortcodes
|
|
self::import('app.controllers.shortcodes');
|
|
|
|
// Charger le gestionnaire de crédits
|
|
self::import('app.controllers.credit_manager');
|
|
}
|
|
} |