/** * Load a given model. * @param string path to file * @example load('blog/model/blog') * @example load('blog/model/blog.php') * @return object */ public static function load($model = false) { $path = DOC_ROOT . Config::get('paths', 'modules'); if ($model && File::isFile($path . $model . '.php')) { $array = explode('/', $model); $modelName = end($array); require $path . $model . '.php'; return new $modelName(); } return false; }
/** * Load a given JavaScript file. * @param string path to file * @return boolean */ public static function js($file = false) { if ($file && !Text::contains($file, '.js')) { $file .= '.js'; } $path = DOC_ROOT . Config::get('paths', 'js'); if ($file && File::isFile($path . $file)) { echo '<script>'; require $path . $file; echo '</script>'; return true; } return false; }
/** * Force a file download by setting headers. * @param string path to file * @param string extension * @param string file name on client side * @example download('folder/error_log.pdf') * @example download('folder/error_log.pdf', 'pdf' ,'log.pdf') * @return boolean */ public static function download($path = false, $extension = false, $name = false) { if ($path && File::isFile($path)) { if (!$extension) { $extension = File::extension($path); } if (!$name) { $name = basename($path); } header('Content-Type: application/' . $extension); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=" . $name); readfile($path); exit; } return false; }
/** * Stack custom config on top of default config to get a complete config array. * If isset static $config, use it to prevent loading a file over and over again. * @param use params to move deeper into array * @return array with merged config */ private static function getConfig() { if (!isset(self::$config)) { $default = Format::jsonToArray(File::get('../config/default.config.json')); $custom = Format::jsonToArray(File::get('../config/custom.config.json')); if ($default && $custom) { self::$config = self::merge($default, $custom); } else { if ($default) { self::$config = $default; } } } if (isset(self::$config)) { return self::$config; } return false; }
/** * Check if given input is a ZIP file. * @param string path to file * @return boolean */ public static function isZip($input = false) { if ($input) { if (File::isFile($input) && File::extension($input) === 'zip') { return true; } } return false; }
/** * Get file content. * @param string path to file * @return boolean */ public static function file($file = false) { return File::get($file); }