protected function filedepot::__construct in filedepot 6
Same name and namespace in other branches
- 7 filedepot.class.php \filedepot::__construct()
File
- ./
filedepot.class.php, line 72 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
protected function __construct() {
# Singleton Pattern: we don't permit an explicit call of the constructor!
global $user;
$this->tmp_storage_path = file_directory_path() . '/filedepot/';
$this->tmp_incoming_path = file_directory_path() . '/filedepot/incoming/';
$this->root_storage_path = variable_get('filedepot_storage_path', str_replace('\\', '/', getcwd()) . '/filedepot_private/');
$this->recordCountPass1 = variable_get('filedepot_pass1_recordcount', 2);
$this->recordCountPass2 = variable_get('filedepot_pass2_recordcount', 10);
$iconsettings = unserialize(variable_get('filedepot_extension_data', ''));
if (!empty($iconsettings)) {
$this->iconmap = array_merge($this->iconmap, $iconsettings);
}
$defOwnerRights = variable_get('filedepot_extension_data', '');
if (!empty($defOwnerRights)) {
$this->defOwnerRights = unserialize($defOwnerRights);
}
else {
$defOwnerRights = array(
'view',
);
}
$permsdata = variable_get('filedepot_default_perms_data', '');
if (!empty($permsdata)) {
$permsdata = unserialize($permsdata);
}
else {
$permsdata = array(
'authenticated user' => array(
'view',
'upload',
),
);
}
if (isset($permsdata['owner']) and count($permsdata['owner'] > 0)) {
$this->defOwnerRights = $permsdata['owner'];
}
else {
$this->defOwnerRights = array(
'view',
'admin',
);
}
if (isset($permsdata['owner'])) {
unset($permsdata['owner']);
// It has now been assigned to defOwnerRights variable
}
$this->defRoleRights = $permsdata;
if (module_exists('og') and module_exists('og_access')) {
$this->ogenabled = TRUE;
}
if (user_is_logged_in()) {
// This cached setting will really only benefit when there are many thousand access records like portal23
// User setting (all users) is cleared each time a folder permission is updated.
// But this library is also included for all AJAX requests
$data = db_result(db_query("SELECT allowable_view_folders FROM {filedepot_usersettings} WHERE uid=%d", $user->uid));
if (empty($data)) {
$this->allowableViewFolders = $this
->getAllowableCategories('view', FALSE);
$data = serialize($this->allowableViewFolders);
if (db_result(db_query("SELECT count(uid) FROM {filedepot_usersettings} WHERE uid=%d", $user->uid)) == 0) {
/* Has a problem handling serialized data - we couldn't unserialize the data afterwards.
* The problem is the pre-constructed SQL statement. When we use the function "udate_sql($sql)",
* we construct the SQL statement without using any argument. A serialized data normally contains curly brackets.
* When you call update_sql($sql), it then hands your pre-constructed $sql to the function db_query($sql).
* Inside the function db_query(), it replace the curly bracket with table prefix blindly,
* even the curly bracket inside data string are converted.
* And thus you will not be able to unserialize the data from the table anymore.
* To get around this, instead of calling update_sql, call db_query($sql, $args).
* Put all the variables to be inserted into the table into the argument list.
* This way db_query will only convert the curly bracket surrounding the table name.
*/
db_query("INSERT INTO {filedepot_usersettings} (uid,allowable_view_folders) VALUES (%d, '%s')", $user->uid, $data);
}
else {
db_query("UPDATE {filedepot_usersettings} set allowable_view_folders='%s' WHERE uid=%d", $data, $user->uid);
}
}
else {
$this->allowableViewFolders = unserialize($data);
}
$this->allowableViewFoldersSql = implode(',', $this->allowableViewFolders);
// Format to use for SQL statement - test for allowable categories
}
else {
$this->allowableViewFolders = $this
->getAllowableCategories('view', FALSE);
$this->allowableViewFoldersSql = implode(',', $this->allowableViewFolders);
// Format to use for SQL statement - test for allowable categories
}
}