1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

Merge pull request #2332 from lonalore/lib

Added getProperty() method.
This commit is contained in:
Cameron
2017-01-27 13:27:23 -08:00
committed by GitHub
2 changed files with 48 additions and 44 deletions

View File

@@ -954,6 +954,23 @@ class e_library_manager
return $directories; return $directories;
} }
/**
* Returns with the selected property of a library.
*
* @param string $library
* Library machine name. For example: bootstrap
*
* @param string $property
* The property name. For example: library_path
*
* @return mixed
*/
public function getProperty($library, $property)
{
$lib = self::info($library);
return varset($lib[$property], false);
}
/** /**
* Returns information about registered libraries. * Returns information about registered libraries.
* *
@@ -1003,48 +1020,32 @@ class e_library_manager
} }
} }
// Gather information from THEME_library::config(). $themes[] = array(
$siteTheme = e107::getPref('sitetheme'); 'name' => e107::getPref('sitetheme'),
$adminTheme = e107::getPref('admintheme'); 'file' => 'theme_library',
'class' => 'theme_library',
);
$themes[] = array(
'name' => e107::getPref('admintheme'),
'file' => 'admin_theme_library',
'class' => 'admin_theme_library',
);
foreach($themes as $theme)
foreach(array($siteTheme, $adminTheme) as $theme)
{ {
if(is_readable(e_THEME . $theme . '/theme_library.php')) // we don't use e_XXXX for themes. if(is_readable(e_THEME . $theme['name'] . '/' . $theme['file'] . '.php'))
{ {
e107_require_once(e_THEME . $theme . '/theme_library.php'); e107_require_once(e_THEME . $theme['name'] . '/' . $theme['file'] . '.php');
$className = 'theme_library'; $info = e107::callMethod($theme['class'], 'config');
if(class_exists($className)) //@todo replace with e107::callMethod();
{
$addonClass = new $className();
if(method_exists($addonClass, 'config'))
{
$info = $addonClass->config();
if(is_array($info)) if(is_array($info))
{ {
foreach($info as $machine_name => $properties) foreach($info as $machine_name => $properties)
{ {
$properties['info_type'] = 'theme'; $properties['info_type'] = 'theme';
$properties['theme'] = $theme; $properties['theme'] = $theme['name'];
$libraries[$machine_name] = $properties; $libraries[$machine_name] = $properties;
if(!in_array($theme, $themes))
{
$themes[] = $theme; // This theme has a valid e_library implementation.
}
}
}
}
if(method_exists($addonClass, 'config_alter'))
{
if(!in_array($theme, $themes))
{
$themes[] = $theme; // This theme has a valid e_library implementation.
}
} }
} }
} }
@@ -1070,21 +1071,24 @@ class e_library_manager
} }
} }
// Allow enabled themes (with theme_library.php file) to alter the registered libraries. // Allow enabled themes to alter the registered libraries.
foreach($themes as $theme) foreach($themes as $theme)
{ {
e107_require_once(e_THEME . $theme . '/theme_library.php'); if(is_readable(e_THEME . $theme['name'] . '/' . $theme['file'] . '.php'))
$addonClass = $theme . '_library';
if(class_exists($addonClass))
{ {
$class = new $addonClass(); e107_require_once(e_THEME . $theme['name'] . '/' . $theme['file'] . '.php');
if(class_exists($theme['class']))
{
$class = new $theme['class']();
if(method_exists($class, 'config_alter')) if(method_exists($class, 'config_alter'))
{ {
// We cannot use e107::callMethod() because need to pass variable by reference.
$class->config_alter($libraries); $class->config_alter($libraries);
} }
} }
} }
}
// TODO: // TODO:
// Invoke callbacks in the 'info' group. // Invoke callbacks in the 'info' group.

View File

@@ -13,7 +13,7 @@
/** /**
* Class bootstrap3_library. * Class theme_library.
*/ */
class theme_library class theme_library
{ {