PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/devtools/ks_prefreport.php

https://gitlab.com/ElvisAns/tiki
PHP | 229 lines | 129 code | 25 blank | 75 comment | 6 complexity | 7b956b7cb936586be05225caf4fd8c14 MD5 | raw file
  1. <?php
  2. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id$
  7. // outputs the prefreport as a pipe delimited file
  8. // Usage: From the command line:
  9. // php doc/devtools/prefreport.php
  10. // resulting file can be found at dump/prefreport.txt
  11. //
  12. // also check out doc/devtools/securitycheck.php to see in which files are
  13. // used each pref (and permission name too)
  14. //
  15. $ourFileName = "dump/prefreport.txt";
  16. require_once 'tiki-setup.php';
  17. $prefslib = TikiLib::lib('prefs');
  18. $defaultValues = get_default_prefs();
  19. $fields = [
  20. 'preference' => '',
  21. 'name' => '',
  22. 'description' => '',
  23. 'default' => '',
  24. 'help' => '',
  25. 'hard_to_search' => false,
  26. 'duplicate_name' => 0,
  27. 'duplicate_description' => 0,
  28. 'word_count' => 0,
  29. 'filter' => '',
  30. 'locations' => '',
  31. 'dependencies' => '',
  32. 'type' => '',
  33. 'options' => '',
  34. 'admin' => '',
  35. 'module' => '',
  36. 'view' => '',
  37. 'permission' => '',
  38. 'plugin' => '',
  39. 'extensions' => '',
  40. 'tags' => '',
  41. 'parameters' => '',
  42. 'detail' => '',
  43. 'warning' => '',
  44. 'hint' => '',
  45. 'shorthint' => '',
  46. 'perspective' => '',
  47. 'separator' => '',
  48. ];
  49. $stopWords = ['', 'in', 'and', 'a', 'to', 'be', 'of', 'on', 'the', 'for', 'as', 'it', 'or', 'with', 'by', 'is', 'an'];
  50. $data = [];
  51. error_reporting(E_ALL);
  52. ini_set('display_errors', 'on');
  53. $data = collect_raw_data($fields);
  54. remove_fake_descriptions($data);
  55. set_default_values($data, $defaultValues);
  56. collect_locations($data);
  57. $index = [
  58. 'name' => index_data($data, 'name'),
  59. 'description' => index_data($data, 'description'),
  60. ];
  61. update_search_flag($data, $index, $stopWords);
  62. $ourFileHandle = fopen($ourFileName, 'w+') or die("can't open file");
  63. // Output results
  64. fputcsv($ourFileHandle, array_keys($fields), '|');
  65. foreach ($data as $values) {
  66. fputcsv($ourFileHandle, array_values($values), '|');
  67. }
  68. fclose($ourFileHandle);
  69. /**
  70. * @param $fields
  71. * @return array
  72. */
  73. function collect_raw_data($fields)
  74. {
  75. $data = [];
  76. foreach (glob('lib/prefs/*.php') as $file) {
  77. $name = substr(basename($file), 0, -4);
  78. $function = "prefs_{$name}_list";
  79. if ($name == 'index') {
  80. continue;
  81. }
  82. include $file;
  83. $list = $function();
  84. foreach ($list as $name => $raw) {
  85. $entry = $fields;
  86. $entry['preference'] = $name;
  87. $entry['name'] = isset($raw['name']) ? $raw['name'] : '';
  88. $entry['description'] = isset($raw['description']) ? $raw['description'] : '';
  89. $entry['filter'] = isset($raw['filter']) ? $raw['filter'] : '';
  90. $entry['help'] = isset($raw['help']) ? $raw['help'] : '';
  91. $entry['dependencies'] = ! empty($raw['dependencies']) ? implode(',', (array) $raw['dependencies']) : '';
  92. $entry['type'] = isset($raw['type']) ? $raw['type'] : '';
  93. $entry['options'] = isset($raw['options']) ? implode(',', $raw['options']) : '';
  94. $entry['admin'] = isset($raw['admin']) ? $raw['admin'] : '';
  95. $entry['module'] = isset($raw['module']) ? $raw['module'] : '';
  96. $entry['view'] = isset($raw['view']) ? $raw['view'] : '';
  97. $entry['permission'] = isset($raw['permission']) ? implode(',', $raw['permission']) : '';
  98. $entry['plugin'] = isset($raw['plugin']) ? $raw['plugin'] : '';
  99. $entry['extensions'] = isset($raw['extensions']) ? implode(',', $raw['extensions']) : '';
  100. $entry['tags'] = isset($raw['tags']) ? implode(',', $raw['tags']) : '';
  101. $entry['parameters'] = isset($raw['parameters']) ? implode(',', $raw['parameters']) : '';
  102. $entry['detail'] = isset($raw['detail']) ? $raw['detail'] : '';
  103. $entry['warning'] = isset($raw['warning']) ? $raw['warning'] : '';
  104. $entry['hint'] = isset($raw['hint']) ? $raw['hint'] : '';
  105. $entry['shorthint'] = isset($raw['shorthint']) ? $raw['shorthint'] : '';
  106. $entry['perspective'] = isset($raw['perspective']) ? $raw['perspective'] ? 'true' : 'false' : '';
  107. $entry['separator'] = isset($raw['separator']) ? $raw['separator'] : '';
  108. $data[] = $entry;
  109. }
  110. }
  111. return $data;
  112. }
  113. /**
  114. * @param $data
  115. */
  116. function remove_fake_descriptions(&$data)
  117. {
  118. foreach ($data as & $row) {
  119. if ($row['name'] == $row['description']) {
  120. $row['description'] = '';
  121. }
  122. }
  123. }
  124. /**
  125. * @param $data
  126. * @param $prefs
  127. */
  128. function set_default_values(&$data, $prefs)
  129. {
  130. foreach ($data as & $row) {
  131. $row['default'] = isset($prefs[$row['preference']]) ? $prefs[$row['preference']] : '';
  132. if (is_array($row['default'])) {
  133. $row['default'] = implode($row['separator'], $row['default']);
  134. }
  135. }
  136. }
  137. /**
  138. * @param $data
  139. * @param $field
  140. * @return array
  141. */
  142. function index_data($data, $field)
  143. {
  144. $index = [];
  145. foreach ($data as $row) {
  146. $value = strtolower($row[$field]);
  147. if (! isset($index[$value])) {
  148. $index[$value] = 0;
  149. }
  150. $index[$value]++;
  151. }
  152. return $index;
  153. }
  154. /**
  155. * @param $data
  156. */
  157. function collect_locations(&$data)
  158. {
  159. $prefslib = TikiLib::lib('prefs');
  160. foreach ($data as & $row) {
  161. $pages = $prefslib->getPreferenceLocations($row['preference']);
  162. foreach ($pages as & $page) {
  163. $page = $page[0] . '/' . $page[1];
  164. }
  165. $row['locations'] = implode(', ', $pages);
  166. }
  167. }
  168. /**
  169. * @param $data
  170. * @param $index
  171. * @param $stopWords
  172. */
  173. function update_search_flag(&$data, $index, $stopWords)
  174. {
  175. foreach ($data as & $row) {
  176. $name = strtolower($row['name']);
  177. $description = strtolower($row['description']);
  178. $words = array_diff(explode(' ', $name . ' ' . $description), $stopWords);
  179. $row['duplicate_name'] = $index['name'][$name];
  180. if (! empty($description)) {
  181. $row['duplicate_description'] = $index['description'][$description];
  182. }
  183. $row['word_count'] = count($words);
  184. if (count($words) < 5) {
  185. $row['hard_to_search'] = 'X';
  186. } elseif ($index['name'][$name] > 2) {
  187. $row['hard_to_search'] = 'X';
  188. } elseif ($index['description'][$description] > 2) {
  189. $row['hard_to_search'] = 'X';
  190. }
  191. }
  192. }