/** * NUpload::connect - Connect NUpload to the specified upload handler * @param string $handler the class name of the upload handler * @return null */ public static function connect($handler) { if (getenv('UPLOAD_PREFIX')) { self::$prefix = getenv('UPLOAD_PREFIX'); } if (!class_exists($handler)) { throw new Exception("Upload handler class doesn't exist", 1); } $handler = new $handler(); if (!$handler instanceof NUpload) { throw new Exception("Upload handler is not instance of NUpload: {$handler}", 1); } self::$handler = $handler; if (method_exists($handler, 'init')) { call_user_func(array(self::$handler, "init"), null); } }
N_DEBUGTYPE_PAGE = 4 = Page debugging N_DEBUGTYPE_CACHE = 8 = Cache handling N_DEBUGTYPE_MENU = 16 = Menu debugging N_DEBUGTYPE_AUTH = 32 = Auth/Login debugging N_DEBUGTYPE_SQL = 64 = SQL debugging N_DEBUGTYPE_ALL = 127 = ALL options */ define('DEBUG_TYPE', 127); define('PAGE_CACHING', true); define('TREE_CACHING', true); // Set this to true if your navigation is actually in the body of each page. // That way, caches are cleared when you make changes to pages to keep your site // consistent. This should probably be set to false on a high traffic site. define('NAV_IN_PAGE', true); // Cache lifetime for files in seconds define('JS_CACHE_LIFETIME', -1); // Backend config is now loaded require_once 'config/config.php'; // To customize which pages cannot be deleted, add their page id's here NConfig::$protectedPages = array(1, 4); // Set the upload handler NUpload::connect(getenv('UPLOAD_HANDLER')); // Sanity check for configuration array_map(function ($env) { if (getenv($env) === false) { error_reporting(0); $error = "{$env} not configured!"; echo $error; throw new Exception($error); } }, array('DB_TYPE', 'DB_SERVER_USERNAME', 'DB_SERVER_PASSWORD', 'DB_SERVER', 'DB_DATABASE'));
function processFiles(&$values, $files_array) { include_once 'n_filesystem.php'; $form =& $this->form; $model =& $this->model; $pk = $model->primaryKey(); foreach ($files_array as $field => $vals) { $tmp_file = $vals['value']['tmp_name']; if (!is_uploaded_file($tmp_file)) { $values[$field] = ''; continue; } $path = array(); if ($vals['type'] == 'cms_file') { $path[] = $this->controller->name; $path[] = $model->{$pk}; } $path[] = substr(md5(microtime()), 20); $path[] = NFilesystem::cleanFileName($vals['value']['name']); $filename = implode('/', $path); $tmp_file = $model->beforeUpload($field, $tmp_file); $newfile = NUpload::moveUpload($tmp_file, $filename); $values[$field] = $newfile ? $newfile : ''; } }