1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Implements hook_feeds_plugins().
|
5 |
|
|
*/
|
6 |
|
|
function feeds_jsonpath_parser_feeds_plugins() {
|
7 |
|
|
$path = drupal_get_path('module', 'feeds_jsonpath_parser');
|
8 |
|
|
$info = array();
|
9 |
|
|
$info['FeedsJSONPathParser'] = array(
|
10 |
|
|
'name' => t('JSONPath parser'),
|
11 |
|
|
'description' => t('Parse JSON using JSONPath.'),
|
12 |
|
|
'handler' => array(
|
13 |
|
|
'parent' => 'FeedsParser',
|
14 |
|
|
'class' => 'FeedsJSONPathParser',
|
15 |
|
|
'file' => 'FeedsJSONPathParser.inc',
|
16 |
|
|
'path' => $path,
|
17 |
|
|
),
|
18 |
|
|
);
|
19 |
|
|
return $info;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* Implements hook_enable().
|
24 |
|
|
*
|
25 |
|
|
* Clear Feed's plugin cache so that this plugin shows up.
|
26 |
|
|
*/
|
27 |
|
|
function feeds_jsonpath_parser_enable() {
|
28 |
|
|
cache_clear_all('plugins:feeds:plugins', 'cache');
|
29 |
|
|
}
|
30 |
7707c013
|
Assos Assos
|
|
31 |
|
|
/**
|
32 |
|
|
* Returns the path of the JSONPath library.
|
33 |
|
|
*
|
34 |
|
|
* @return string|bool
|
35 |
|
|
* The relative path of the JSONPath directory, or false if not found.
|
36 |
|
|
*/
|
37 |
|
|
function feeds_jsonpath_parser_library_path() {
|
38 |
|
|
$libraries_path = module_exists('libraries') ? libraries_get_path('jsonpath') : FALSE;
|
39 |
|
|
if ($libraries_path && is_dir($libraries_path)) {
|
40 |
|
|
$path = $libraries_path;
|
41 |
|
|
}
|
42 |
|
|
elseif (is_dir(DRUPAL_ROOT . '/sites/all/libraries/jsonpath')) {
|
43 |
|
|
$path = DRUPAL_ROOT . '/sites/all/libraries/jsonpath';
|
44 |
|
|
}
|
45 |
|
|
// This is defined when simpletest downloads the library for us.
|
46 |
|
|
elseif (variable_get('feeds_jsonpath_library_dir')) {
|
47 |
|
|
$path = variable_get('feeds_jsonpath_library_dir');
|
48 |
|
|
}
|
49 |
|
|
else {
|
50 |
|
|
$search = glob(dirname(__FILE__) . '/jsonpath*.php');
|
51 |
|
|
return is_array($search) ? reset($search) : FALSE;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
if (!isset($path)) {
|
55 |
|
|
return FALSE;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// Newer forks of JSONPath are all modern and fancy with their autoloaders.
|
59 |
|
|
if (is_file($path . '/vendor/autoload.php')) {
|
60 |
|
|
return $path . '/vendor/autoload.php';
|
61 |
|
|
}
|
62 |
|
|
// Old school. Look for multiple versions.
|
63 |
|
|
foreach (glob($path . '/jsonpath*.php') as $file) {
|
64 |
|
|
return $file;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
return FALSE;
|
68 |
|
|
} |