Commit e5962daf authored by amool's avatar amool Committed by Konstantin Komelin
Browse files

Issue #2199489 by amool, konstantin.komelin: Implemented hook_requirements for...

Issue #2199489 by amool, konstantin.komelin: Implemented hook_requirements for simplehtmldom library.
parent 3cdda605
simplehtmldom 7.x-2.x, xxxx-xx-xx
#2199489 by amool, konstantin.komelin: Implemented hook_requirements for simplehtmldom library.
simplehtmldom 7.x-2.0, 2014-02-16
Removed simplehtmldom library from the module package
......
<?php
/**
* @file
* Helper functions.
*/
/**
* Returns path of simplhtmldom library.
*
* @return bool|string
* Path to the library.
*/
function _simplhtmldom_get_library_path() {
$file = 'simple_html_dom.php';
$library = 'simplehtmldom';
// Implement simple cache.
$library_path = &drupal_static(__FUNCTION__);
if (!empty($library_path)) {
return $library_path;
}
// Support libraries module.
if (module_exists('libraries') && function_exists('libraries_get_path')) {
$library_path = libraries_get_path($library) . "/$file";
if (file_exists($library_path)) {
return $library_path;
}
}
else {
$paths = array(
'sites/all/libraries/' . $library,
drupal_get_path('module', 'simplehtmldom') . '/' . $library,
drupal_get_path('module', 'simplehtmldom') . "/libraries",
'profiles/' . variable_get('install_profile', 'default') . '/libraries/' . $library,
);
foreach ($paths as $library_dir) {
$library_path = $library_dir . "/$file";
if (file_exists($library_path)) {
return $library_path;
}
}
}
return FALSE;
}
<?php
/**
* @file
* Install, update and requirements hooks for the module.
*/
/**
* Implements hook_requirements().
*/
function simplehtmldom_requirements($phase) {
$requirements = array();
// Ensure translations do not break at install time.
$t = get_t();
$requirements['simple_html_dom'] = array(
'title' => $t('"PHP Simple HTML DOM Parser" library'),
);
// Include the helper file.
module_load_include('inc', 'simplehtmldom', 'helper');
if (_simplhtmldom_get_library_path()) {
$requirements['simple_html_dom']['value'] = $t('Installed');
$requirements['simple_html_dom']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['simple_html_dom']['value'] = $t('not installed');
$requirements['simple_html_dom']['severity'] = REQUIREMENT_ERROR;
$requirements['simple_html_dom']['description'] = $t('simple_html_dom.php is missing. Please copy the latest version of simple_html_dom.php (PHP Simple HTML DOM Parser library) from http://sourceforge.net/projects/simplehtmldom/ to you libraries folder, for example sites/all/libraries/simplehtmldom/simple_html_dom.php');
}
return $requirements;
}
......@@ -7,6 +7,9 @@
* But these names are quite rare to cause collisions.
*/
// Include the helper file.
module_load_include('inc', 'simplehtmldom', 'helper');
if (!function_exists('str_get_html')) {
$simplehtmldom_library_path = _simplhtmldom_get_library_path();
if (!empty($simplehtmldom_library_path)) {
......@@ -17,45 +20,6 @@ else {
drupal_set_message(t('The simplehtmldom API module found that you define its functions before it does itself! Somewhere in your drupal files there must be a copy of the PHP Simple HTML DOM Parser library that you do not need if you use this module. Please remove the old library or move it to sites/all/libraries/simplehtmldom folder.'), 'error');
}
/**
* Returns path of simplhtmldom library.
*
* @return bool|string
* Path to library.
*/
function _simplhtmldom_get_library_path() {
// Implement simple cache.
$library_path = &drupal_static(__FUNCTION__);
if (!empty($library_path)) {
return $library_path;
}
$file = 'simple_html_dom.php';
$library = 'simplehtmldom';
// Support libraries module.
if (module_exists('libraries') && function_exists('libraries_get_path')) {
$path = libraries_get_path($library) . "/$file";
if (file_exists($path)) {
return $path;
}
}
else {
$paths = array(
'sites/all/libraries/' . $library,
drupal_get_path('module', 'simplehtmldom') . '/' . $library,
drupal_get_path('module', 'simplehtmldom') . "/libraries",
'profiles/' . variable_get('install_profile', 'default') . '/libraries/' . $library,
);
foreach ($paths as $library_path) {
$path = $library_path . "/$file";
if (file_exists($path)) {
return $path;
}
}
}
return FALSE;
}
/**
* Implements hook_libraries_info().
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment