/** * 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; }
/** * 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; }