From 29848076251242461569af79a44bee0a992fd02f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 4 Feb 2016 13:14:13 -0700 Subject: [PATCH] API Explorer: Use Civi::paths instead of global $civicrm_root --- CRM/Admin/Page/APIExplorer.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/CRM/Admin/Page/APIExplorer.php b/CRM/Admin/Page/APIExplorer.php index de63dbc997..bc2d6ec732 100644 --- a/CRM/Admin/Page/APIExplorer.php +++ b/CRM/Admin/Page/APIExplorer.php @@ -51,9 +51,8 @@ class CRM_Admin_Page_APIExplorer extends CRM_Core_Page { $this->assign('operators', CRM_Core_DAO::acceptedSQLOperators()); // List example directories - global $civicrm_root; $examples = array(); - foreach (scandir(CRM_Utils_file::addTrailingSlash($civicrm_root, '/') . 'api/v3/examples') as $item) { + foreach (scandir(\Civi::paths()->getPath('[civicrm.root]/api/v3/examples')) as $item) { if ($item && strpos($item, '.') === FALSE) { $examples[] = $item; } @@ -77,11 +76,9 @@ class CRM_Admin_Page_APIExplorer extends CRM_Core_Page { * AJAX callback to fetch examples. */ public static function getExampleFile() { - global $civicrm_root; - $basePath = CRM_Utils_file::addTrailingSlash($civicrm_root, '/'); if (!empty($_GET['entity']) && strpos($_GET['entity'], '.') === FALSE) { $examples = array(); - foreach (scandir($basePath . 'api/v3/examples/' . $_GET['entity']) as $item) { + foreach (scandir(\Civi::paths()->getPath("[civicrm.root]/api/v3/examples/{$_GET['entity']}")) as $item) { $item = str_replace('.php', '', $item); if ($item && strpos($item, '.') === FALSE) { $examples[] = array('key' => $item, 'value' => $item); @@ -90,7 +87,7 @@ class CRM_Admin_Page_APIExplorer extends CRM_Core_Page { CRM_Utils_JSON::output($examples); } if (!empty($_GET['file']) && strpos($_GET['file'], '.') === FALSE) { - $fileName = $basePath . 'api/v3/examples/' . $_GET['file'] . '.php'; + $fileName = \Civi::paths()->getPath("[civicrm.root]/api/v3/examples/{$_GET['file']}.php"); if (file_exists($fileName)) { echo file_get_contents($fileName); } -- 2.25.1