addScriptFile('civicrm', 'templates/CRM/Admin/Page/APIExplorer.js') ->addScriptUrl('//cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js', 99) ->addStyleUrl('//cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css', 99); $this->assign('operators', CRM_Core_DAO::acceptedSQLOperators()); // List example directories global $civicrm_root; $examples = array(); foreach (scandir($civicrm_root . 'api/v3/examples') as $item) { if ($item && strpos($item, '.') === FALSE) { $examples[] = $item; } } $this->assign('examples', $examples); return parent::run(); } /** * Get user context. * * @return string * user context. */ public function userContext() { return 'civicrm/api/explorer'; } /** * AJAX callback to fetch examples */ public static function getExampleFile() { global $civicrm_root; if (!empty($_GET['entity']) && strpos($_GET['entity'], '.') === FALSE) { $examples = array(); foreach (scandir($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); } } CRM_Utils_JSON::output($examples); } if (!empty($_GET['file']) && strpos($_GET['file'], '.') === FALSE) { $fileName = $civicrm_root . 'api/v3/examples/' . $_GET['file'] . '.php'; if (file_exists($fileName)) { echo file_get_contents($fileName); } else { echo "Not found."; } CRM_Utils_System::civiExit(); } } }