@@ -100,6 +100,7 @@ class KB_Router extends CI_Router
100100 'routes ' => array (),
101101 'admin_menu ' => null ,
102102 'admin_order ' => 0 ,
103+ 'textdomain ' => null ,
103104 'translations ' => array (),
104105 );
105106
@@ -470,7 +471,7 @@ public function list_modules($details = false)
470471 public function _load_modules ()
471472 {
472473 // Make sure we have some enabled modules first.
473- $ active = $ this ->active_modules ();
474+ $ active = $ this ->active_modules (true );
474475 if (empty ($ active ))
475476 {
476477 return ;
@@ -479,33 +480,33 @@ public function _load_modules()
479480 // Prepare our list of modules.
480481 $ modules = $ this ->list_modules ();
481482
482- foreach ($ active as $ folder )
483+ foreach ($ active as $ folder => $ m )
483484 {
484485 // Module enabled but folder missing? Nothing to do.
485- if ( ! isset ( $ modules [ $ folder ]))
486+ if ( ! is_dir ( $ m [ ' full_path ' ]))
486487 {
487488 continue ;
488489 }
489490
490491 // "init.php" not found? Nothing to do.
491- if ( ! is_file ($ modules [ $ folder ].'init.php ' ))
492+ if ( ! is_file ($ m [ ' full_path ' ].'init.php ' ))
492493 {
493494 continue ;
494495 }
495496
496497 // Import "init.php" file.
497- require_once ($ modules [ $ folder ].'init.php ' );
498+ require_once ($ m [ ' full_path ' ].'init.php ' );
498499
499500 /**
500501 * If a "module_activate_" action was registered, we fire
501502 * it and make sure to add the "enabled" file. This way we
502503 * avoid firing it again.
503504 */
504505 if (has_action ('module_activate_ ' .$ folder )
505- && ! is_file ($ modules [ $ folder ].'enabled ' ))
506+ && ! is_file ($ m [ ' full_path ' ].'enabled ' ))
506507 {
507508 do_action ('module_activate_ ' .$ folder );
508- @touch ($ modules [ $ folder ].'enabled ' );
509+ @touch ($ m [ ' full_path ' ].'enabled ' );
509510 }
510511
511512 // We always fire this action.
@@ -518,11 +519,11 @@ public function _load_modules()
518519 * @since 2.1.0
519520 */
520521 if (function_exists ('gettext_instance ' )
521- && is_dir ($ modules [ $ folder ].'language ' ))
522+ && is_dir ($ m [ ' full_path ' ].'language ' ))
522523 {
523524 gettext_instance ()->bindtextdomain (
524- $ folder ,
525- $ modules [ $ folder ].'language '
525+ is_string ( $ m [ ' textdomain ' ]) ? $ m [ ' textdomain ' ] : $ folder ,
526+ $ m [ ' full_path ' ].'language '
526527 );
527528 }
528529 }
@@ -1346,3 +1347,196 @@ function disable_module($name)
13461347 return get_instance ()->router ->module_deactivate ($ name );
13471348 }
13481349}
1350+
1351+ // ------------------------------------------------------------------------
1352+
1353+ if ( ! function_exists ('is_admin ' ))
1354+ {
1355+ function is_admin ()
1356+ {
1357+ return get_instance ()->router ->is_admin ();
1358+ }
1359+ }
1360+
1361+ // ------------------------------------------------------------------------
1362+ // Module's helpers.
1363+ // ------------------------------------------------------------------------
1364+
1365+ if ( ! function_exists ('get_the_module ' ))
1366+ {
1367+ /**
1368+ * Returns the current module folder's name.
1369+ * @param none
1370+ * @return string Folder name if found, else null.
1371+ */
1372+ function get_the_module ()
1373+ {
1374+ return get_instance ()->router ->fetch_module ();
1375+ }
1376+ }
1377+
1378+ // ------------------------------------------------------------------------
1379+
1380+ if ( ! function_exists ('the_module ' ))
1381+ {
1382+ /**
1383+ * Displays the current module folder's name.
1384+ * @param none
1385+ * @return void
1386+ */
1387+ function the_module ()
1388+ {
1389+ echo get_instance ()->router ->fetch_module ();
1390+ }
1391+ }
1392+
1393+ // ------------------------------------------------------------------------
1394+
1395+ if ( ! function_exists ('is_module ' ))
1396+ {
1397+ /**
1398+ * Checks if the page belongs to a given module. If no argument is passed,
1399+ * it checks if we areusing a module.
1400+ * You may pass a single string, multiple comma- separated modules or an array.
1401+ * @param string|array.
1402+ * @return bool true if passed check, else false.
1403+ */
1404+ function is_module ($ modules = null )
1405+ {
1406+ $ module = get_instance ()->router ->fetch_module ();
1407+
1408+ if (null === $ modules )
1409+ {
1410+ return ($ module !== null );
1411+ }
1412+
1413+ if ( ! is_array ($ modules ))
1414+ {
1415+ $ modules = explode (', ' , $ modules );
1416+ }
1417+
1418+ $ modules = array_clean ($ modules );
1419+
1420+ return in_array ($ module , $ modules );
1421+ }
1422+ }
1423+
1424+ // ------------------------------------------------------------------------
1425+ // Controller's helpers.
1426+ // ------------------------------------------------------------------------
1427+
1428+ if ( ! function_exists ('get_the_controller ' ))
1429+ {
1430+ /**
1431+ * Returns the current controller folder's name.
1432+ * @param none
1433+ * @return string Class name if found, else null.
1434+ */
1435+ function get_the_controller ()
1436+ {
1437+ return get_instance ()->router ->fetch_class ();
1438+ }
1439+ }
1440+
1441+ // ------------------------------------------------------------------------
1442+
1443+ if ( ! function_exists ('the_controller ' ))
1444+ {
1445+ /**
1446+ * Displays the current controller folder's name.
1447+ * @param none
1448+ * @return void
1449+ */
1450+ function the_controller ()
1451+ {
1452+ echo get_instance ()->router ->fetch_class ();
1453+ }
1454+ }
1455+
1456+ // ------------------------------------------------------------------------
1457+
1458+ if ( ! function_exists ('is_controller ' ))
1459+ {
1460+ /**
1461+ * Checks if the page belongs to a given controller.
1462+ * @param mixed $controllers
1463+ * @return bool
1464+ */
1465+ function is_controller ($ controllers = null )
1466+ {
1467+ $ controller = get_instance ()->router ->fetch_class ();
1468+
1469+ if (null === $ controllers )
1470+ {
1471+ return ($ controller !== null );
1472+ }
1473+
1474+ if ( ! is_array ($ controllers ))
1475+ {
1476+ $ controllers = explode (', ' , $ controllers );
1477+ }
1478+
1479+ $ controllers = array_clean ($ controllers );
1480+
1481+ return in_array ($ controller , $ controllers );
1482+ }
1483+ }
1484+
1485+ // ------------------------------------------------------------------------
1486+ // Method's helpers.
1487+ // ------------------------------------------------------------------------
1488+
1489+ if ( ! function_exists ('get_the_method ' ))
1490+ {
1491+ /**
1492+ * Returns the current method's name.
1493+ * @return string
1494+ */
1495+ function get_the_method ()
1496+ {
1497+ return get_instance ()->router ->fetch_method ();
1498+ }
1499+ }
1500+
1501+ // --------------------------------------------------------------------
1502+
1503+ if ( ! function_exists ('the_method ' ))
1504+ {
1505+ /**
1506+ * Returns the current method's name.
1507+ * @return void
1508+ */
1509+ function the_method ()
1510+ {
1511+ echo get_instance ()->router ->fetch_method ();
1512+ }
1513+ }
1514+
1515+ // ------------------------------------------------------------------------
1516+
1517+ if ( ! function_exists ('is_method ' ))
1518+ {
1519+ /**
1520+ * Checks if the page belongs to a given method.
1521+ * @return bool
1522+ */
1523+ function is_method ($ methods = null )
1524+ {
1525+ $ method = get_instance ()->router ->fetch_method ();
1526+
1527+ // This is silly but, let's just put it.
1528+ if (null === $ methods )
1529+ {
1530+ return ($ method !== null );
1531+ }
1532+
1533+ if ( ! is_array ($ methods ))
1534+ {
1535+ $ methods = explode (', ' , $ methods );
1536+ }
1537+
1538+ $ methods = array_clean ($ methods );
1539+
1540+ return (in_array ($ method , $ methods ));
1541+ }
1542+ }
0 commit comments