Changeset 14119

Show
Ignore:
Timestamp:
05/30/12 03:10:38 (1 year ago)
Author:
mbrevda
Message:

function to recursivly remove a directory

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.10/amp_conf/htdocs/admin/libraries/utility.functions.php

    r14049 r14119  
    12951295  return preg_replace('/[^[:print:]]/', '', $cid); 
    12961296} 
     1297 
     1298/** 
     1299 * Recursivly remove a directory 
     1300 * @param string - dirname 
     1301 * 
     1302 * @return bool 
     1303 */ 
     1304function rrmdir($dir) { 
     1305  foreach(glob($dir . '/*') as $file) { 
     1306    if(is_dir($file)) 
     1307      rrmdir($file); 
     1308    else 
     1309      unlink($file); 
     1310    } 
     1311    rmdir($dir); 
     1312 
     1313  return !is_dir($dir); 
     1314} 
     1315 
     1316/** 
     1317 * Run bootstrap hooks as provided by module.xml 
     1318 * 
     1319 * We currently support hooking at two points: before modules are loaded and after modules are loaded 
     1320 * Before we load ANY modules, we will include all "all_mods" hooks 
     1321 * Before we load an indevidual module, we will load there specifc hook 
     1322 * 
     1323 * @param string - hook type 
     1324 * @param string - module name 
     1325 * 
     1326 */ 
     1327function bootstrap_include_hooks($hook_type, $module) { 
     1328  global $amp_conf; 
     1329  //first parse and load all hook info 
     1330  if (!isset($hooks)) { 
     1331    static $hooks = ''; 
     1332    $hooks = _bootstrap_parse_hooks(); 
     1333     
     1334  } 
     1335   
     1336  if (isset($hooks[$hook_type][$module])) { 
     1337    foreach ($hooks[$hook_type][$module] as $hook) { 
     1338      if (file_exists($hook)) { 
     1339        require_once($hook); 
     1340      } elseif(file_exists($amp_conf['AMPWEBROOT'] . '/admin/' . $hook)) { 
     1341        require_once($amp_conf['AMPWEBROOT'] . '/admin/' . $hook); 
     1342      } 
     1343       
     1344    } 
     1345  } 
     1346   
     1347  return true; 
     1348} 
     1349 
     1350/** 
     1351 * Helper function to laod hooks for bootstrap_include_hooks() 
     1352 */ 
     1353function _bootstrap_parse_hooks() { 
     1354  $hooks    = array(); 
     1355   
     1356  $modules  = module_getinfo(false, MODULE_STATUS_ENABLED); 
     1357  foreach ($modules as $mymod => $mod) { 
     1358    if (isset($mod['bootstrap_hooks'])) { 
     1359      foreach ($mod['bootstrap_hooks'] as $type => $type_mods) { 
     1360        switch ($type) { 
     1361          case 'pre_module_load': 
     1362          case 'post_module_load': 
     1363            //first get all_mods 
     1364            if (isset($type_mods['all_mods'])) { 
     1365               
     1366              $hooks[$type]['all_mods'] = isset($hooks[$type]['all_mods'])  
     1367                            ? array_merge($hooks[$type]['all_mods'],  
     1368                             (array)$type_mods['all_mods']) 
     1369                            : (array)$type_mods['all_mods']; 
     1370              unset($type_mods['all_mods']);   
     1371            } 
     1372            if (!isset($type_mods)) { 
     1373              break;//break if there are no more hooks to include 
     1374            } 
     1375            //now load all remaining modules 
     1376            foreach ($type_mods as $type_mod) { 
     1377              $hooks[$type][$mymod] = isset($hooks[$type][$mymod]) 
     1378                          ? array_merge($hooks[$type][$mymod],  
     1379                          (array)$type_mod) 
     1380                          : (array)$type_mod; 
     1381            } 
     1382            break; 
     1383          default: 
     1384            break; 
     1385        } 
     1386      } 
     1387    } 
     1388  } 
     1389  return $hooks; 
     1390}