Merge pull request #19757 from eileenmcnaughton/tax_amount
[civicrm-core.git] / tools / bin / scripts / ckeditorConfigScraper.php
1 <?php
2 if (!(php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))) {
3 header("HTTP/1.0 404 Not Found");
4 return;
5 }
6 /**
7 * Scrape all config options from the CKEditor documentation site.
8 */
9 $content = file_get_contents('http://docs.ckeditor.com/?print=/api/CKEDITOR.config');
10 $matches = $output = [];
11 preg_match_all("#name expandable'>([^<]+)</a>\s?:\s?(.*)<span.*'short'>([\s\S]*?)</div>#", $content, $matches);
12 foreach ($matches[1] as $i => $name) {
13 $output[] = [
14 'id' => $name,
15 'type' => strip_tags($matches[2][$i]),
16 'description' => str_replace(["\n", '. ...'], [' ', '.'], $matches[3][$i]),
17 ];
18 }
19 if ($output) {
20 $location = str_replace('tools/bin/scripts', '', __DIR__);
21 file_put_contents($location . '/js/wysiwyg/ck-options.json', json_encode($output, JSON_PRETTY_PRINT));
22 }
23 print "\nTotal: " . count($output) . "\n";