Merge pull request #20486 from civicrm/5.38
[civicrm-core.git] / tools / bin / scripts / ckeditorConfigScraper.php
CommitLineData
3b7ceeb2 1<?php
5c5ed6db 2if (!(php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))) {
a9f3bf65
SL
3 header("HTTP/1.0 404 Not Found");
4 return;
5}
3b7ceeb2
CW
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');
b7c0a88f 10$matches = $output = [];
3b7ceeb2
CW
11preg_match_all("#name expandable'>([^<]+)</a>\s?:\s?(.*)<span.*'short'>([\s\S]*?)</div>#", $content, $matches);
12foreach ($matches[1] as $i => $name) {
b7c0a88f 13 $output[] = [
3b7ceeb2
CW
14 'id' => $name,
15 'type' => strip_tags($matches[2][$i]),
b7c0a88f 16 'description' => str_replace(["\n", '. ...'], [' ', '.'], $matches[3][$i]),
17 ];
3b7ceeb2
CW
18}
19if ($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}
23print "\nTotal: " . count($output) . "\n";