| | 564 | |
|---|
| | 565 | /** |
|---|
| | 566 | * add a directory where patForms should search for |
|---|
| | 567 | * modules. |
|---|
| | 568 | * |
|---|
| | 569 | * You may either pass a string or an array of directories. |
|---|
| | 570 | * |
|---|
| | 571 | * patTemplate will be searching for a module in the same |
|---|
| | 572 | * order you added them. If the module cannot be found in |
|---|
| | 573 | * the custom folders, it will look in |
|---|
| | 574 | * patForms/$moduleType. |
|---|
| | 575 | * |
|---|
| | 576 | * @static |
|---|
| | 577 | * @access public |
|---|
| | 578 | * @param string module type or NULL for any |
|---|
| | 579 | * @param string|array directory or directories to search. |
|---|
| | 580 | */ |
|---|
| | 581 | function addModuleDir($moduleType, $dir) |
|---|
| | 582 | { |
|---|
| | 583 | $dirs =& patForms::getStaticProperty( 'moduleDirs' ); |
|---|
| | 584 | |
|---|
| | 585 | if (!is_array($dir)) { |
|---|
| | 586 | $dir = array($dir); |
|---|
| | 587 | } |
|---|
| | 588 | |
|---|
| | 589 | if ($moduleType === null) { |
|---|
| | 590 | $dirs['__all'] = array_merge($dirs['__all'], $dir); |
|---|
| | 591 | return true; |
|---|
| | 592 | } |
|---|
| | 593 | |
|---|
| | 594 | if (!isset($dirs[$moduleType])) { |
|---|
| | 595 | $dirs[$moduleType] = array(); |
|---|
| | 596 | } |
|---|
| | 597 | |
|---|
| | 598 | $dirs[$moduleType] = array_merge($dirs[$moduleType], $dir); |
|---|
| | 599 | return true; |
|---|
| | 600 | } |
|---|
| | 601 | |
|---|
| | 602 | /** |
|---|
| | 603 | * add a base directory where patForms should search for |
|---|
| | 604 | * modules. |
|---|
| | 605 | * |
|---|
| | 606 | * You may either pass a string or an array of directories. |
|---|
| | 607 | * |
|---|
| | 608 | * patForms will be searching for a module in the same |
|---|
| | 609 | * order you added them. It will first look in module specific |
|---|
| | 610 | * directory (added with addModuleDir()), afterwards in module |
|---|
| | 611 | * base dirs. If the module cannot be found in the custom |
|---|
| | 612 | * folders, it will look in patForms/$moduleType. |
|---|
| | 613 | * |
|---|
| | 614 | * @static |
|---|
| | 615 | * @access public |
|---|
| | 616 | * @param string|array directory or directories to search. |
|---|
| | 617 | * @see addModuleDir() |
|---|
| | 618 | */ |
|---|
| | 619 | function addModuleBaseDir($dir) |
|---|
| | 620 | { |
|---|
| | 621 | return patForms::addModuleDir(null, $dir); |
|---|
| | 622 | } |
|---|
| 1500 | | $moduleFile = PATFORMS_INCLUDE_PATH . '/'.$type.'/'.$pathName.'.php'; |
|---|
| 1501 | | $moduleClass = 'patForms_'.$type.'_'.$name; |
|---|
| 1502 | | |
|---|
| 1503 | | |
|---|
| 1504 | | if (!class_exists($moduleClass)) { |
|---|
| 1505 | | if (!file_exists( $moduleFile)) { |
|---|
| 1506 | | $error = patErrorManager::raiseError( |
|---|
| 1507 | | PATFORMS_ERROR_MODULE_NOT_FOUND, |
|---|
| 1508 | | $type.' "'.$name.'" file "'.$moduleFile. '" could not be found.' |
|---|
| 1509 | | ); |
|---|
| 1510 | | return $error; |
|---|
| 1511 | | } |
|---|
| 1512 | | include_once $moduleFile; |
|---|
| 1513 | | } |
|---|
| | 1575 | // where are the include folders? |
|---|
| | 1576 | $moduleDirs = patForms::getStaticProperty('moduleDirs'); |
|---|
| | 1577 | |
|---|
| | 1578 | // special module dirs |
|---|
| | 1579 | if (!isset( $moduleDirs[$type])) { |
|---|
| | 1580 | $moduleDirs[$type] = array(); |
|---|
| | 1581 | } |
|---|
| | 1582 | |
|---|
| | 1583 | // other module folder follow standard directory structure |
|---|
| | 1584 | foreach ($moduleDirs['__all'] as $all) { |
|---|
| | 1585 | $moduleDirs[$type][] = $all . '/' . $type; |
|---|
| | 1586 | } |
|---|
| | 1587 | |
|---|
| | 1588 | // patForms standard folder |
|---|
| | 1589 | $moduleDirs[$type][] = PATFORMS_INCLUDE_PATH . '/' . $type; |
|---|
| | 1590 | |
|---|
| | 1591 | $found = false; |
|---|
| | 1592 | foreach ($moduleDirs[$type] as $dir) { |
|---|
| | 1593 | if (!file_exists($dir . '/' . $pathName . '.php')) { |
|---|
| | 1594 | continue; |
|---|
| | 1595 | } |
|---|
| | 1596 | |
|---|
| | 1597 | include_once $dir . '/' . $pathName . '.php'; |
|---|
| | 1598 | $found = true; |
|---|
| | 1599 | break; |
|---|
| | 1600 | } |
|---|
| | 1601 | |
|---|
| | 1602 | if (!$found) { |
|---|
| | 1603 | $error =& patErrorManager::raiseError( |
|---|
| | 1604 | PATFORMS_ERROR_MODULE_NOT_FOUND, |
|---|
| | 1605 | $type.' "'.$name.'" could not be found in module dirs: "'. implode( '", "', $moduleDirs[$type] ) .'".' |
|---|
| | 1606 | ); |
|---|
| | 1607 | return $error; |
|---|
| | 1608 | } |
|---|
| | 1609 | |
|---|