public static function removeDir($dir) { if (!file_exists($dir)) { return true; } if (!is_dir($dir)) { return unlink($dir); } foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') { continue; } if (!Vi_Folder::removeDir($dir . DIRECTORY_SEPARATOR . $item)) { return false; } } return Vi_Folder::removeDir($dir); }
public function rescanAction() { /** * Check permission */ if (false == $this->checkPermission('rescan_permission')) { $this->_forwardToNoPermissionPage(); return; } /** * Get all current permissions */ $objPer = new Models_Permission(); $allPers = $objPer->getAll(); /** * Get all applications */ $allApps = Vi_Folder::getFolders('applications'); foreach ($allApps as $index => $app) { if (is_dir("applications/{$app}")) { /** * Check to all current application permissions */ $flag = false; foreach ($allPers as $per) { if ($per['name'] == 'access' && $per['module'] == "application::{$app}") { $flag = true; break; } } if (false == $flag) { /** * New application is found */ $objPer->insert(array('name' => 'access', 'module' => "application::{$app}", 'description' => "Access to '{$app}' application")); } } } /** * Get all modules */ $allModules = Vi_Folder::getFolders('modules'); foreach ($allModules as $index => $module) { if (is_dir("modules/{$module}")) { /** * Get permission file */ $configPers = @(include "modules/{$module}/config.php"); $configPers = @$configPers['permissionRules']; if (!is_array($configPers) || empty($configPers)) { /** * Clear all permissions of this module */ $objPer->delete(array('module=?' => $module)); continue; } /** * Check to match permisison */ $existIds = array(); foreach ($configPers as $key => $desc) { if (is_array($desc)) { /** * Expandable permission * $per is array with 3 elements */ $flag = false; foreach ($allPers as $per) { if (null == @$desc[0] || null == @$desc[1] || null == @$desc[2] || null == @$desc[3]) { throw new Exception("Module '{$module}' has config with wrong expanded permission rules. \r\n It has to be array with 4 elements: Permisison string, expand_table_name, expand_table_id, expand_display_name"); } if ($per['name'] == $key && $per['module'] == $module) { $existIds[] = $per['permission_id']; $flag = true; if ($desc[0] != $per['description'] || $desc[1] != $per['expand_table_name'] || $desc[2] != $per['expand_table_id'] || $desc[3] != $per['expand_display_name']) { $per->description = $desc[0]; $per->expand_table_name = $desc[1]; $per->expand_table_id = $desc[2]; $per->expand_display_name = $desc[3]; $per->save(); } break; } } if (false == $flag) { /** * New permisison rule */ $objPer->insert(array('name' => $key, 'module' => $module, 'description' => $desc[0], 'expand_table_name' => $desc[1], 'expand_table_id' => $desc[2], 'expand_display_name' => $desc[3])); } } else { /** * Nomarl permission * * $per is string */ $flag = false; foreach ($allPers as $per) { if ($per['name'] == $key && $per['module'] == $module) { $existIds[] = $per['permission_id']; $flag = true; if ($per['description'] != $desc || NULL != $per['expand_table_name'] || NULL != $per['expand_table_id'] || NULL != $per['expand_display_name']) { $per->description = $desc; $per->expand_table_name = NULL; $per->expand_table_id = NULL; $per->expand_display_name = NULL; $per->save(); } break; } } if (false == $flag) { /** * New permisison rule */ $objPer->insert(array('name' => $key, 'module' => $module, 'description' => $desc)); } } } /** * Clear all un-used permission */ foreach ($allPers as $per) { if ($per['module'] == $module && !in_array($per['permission_id'], $existIds)) { $objPer->delete(array('permission_id=?' => $per['permission_id'])); } } } } $this->session->permissionMessage = array('success' => true, 'message' => Vi_Language::translate('Rescan all permission rules successfully')); $this->_redirect('permission/admin/manager'); }
private function getAllStickerRoot() { $folders = Vi_Folder::getFolders('stickers'); $results = array(); foreach ($folders as $key => $val) { $configFile = "stickers/{$val}/config.php"; $sticker = array('name' => $val, 'title' => 'no title', 'params' => array()); if (is_file($configFile)) { $config = (include $configFile); if (is_array($config)) { if (isset($config['params'])) { $paramsList = $config['params']; $params = array(); foreach ($paramsList as $item) { $params[$item['name']] = $item['default']; } if (isset($config['defaultTitle'])) { $sticker['title'] = $config['defaultTitle']; } $sticker['params'] = $params; } if (isset($config['dragAndDroppable']) && $config['dragAndDroppable']) { $results[] = $sticker; } } } } return $results; }