@@ -24,55 +24,55 @@ |
||
24 | 24 | * Class PedigreeChartModule |
25 | 25 | */ |
26 | 26 | class PedigreeChartModule extends AbstractModule implements ModuleChartInterface { |
27 | - /** |
|
28 | - * How should this module be labelled on tabs, menus, etc.? |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function getTitle() { |
|
33 | - return /* I18N: Name of a module/chart */ I18N::translate('Pedigree'); |
|
34 | - } |
|
27 | + /** |
|
28 | + * How should this module be labelled on tabs, menus, etc.? |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function getTitle() { |
|
33 | + return /* I18N: Name of a module/chart */ I18N::translate('Pedigree'); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * A sentence describing what this module does. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function getDescription() { |
|
42 | - return /* I18N: Description of the “PedigreeChart” module */ I18N::translate('A chart of an individual’s ancestors, formatted as a tree.'); |
|
43 | - } |
|
36 | + /** |
|
37 | + * A sentence describing what this module does. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function getDescription() { |
|
42 | + return /* I18N: Description of the “PedigreeChart” module */ I18N::translate('A chart of an individual’s ancestors, formatted as a tree.'); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * What is the default access level for this module? |
|
47 | - * |
|
48 | - * Some modules are aimed at admins or managers, and are not generally shown to users. |
|
49 | - * |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function defaultAccessLevel() { |
|
53 | - return Auth::PRIV_PRIVATE; |
|
54 | - } |
|
45 | + /** |
|
46 | + * What is the default access level for this module? |
|
47 | + * |
|
48 | + * Some modules are aimed at admins or managers, and are not generally shown to users. |
|
49 | + * |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function defaultAccessLevel() { |
|
53 | + return Auth::PRIV_PRIVATE; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Return a menu item for this chart. |
|
58 | - * |
|
59 | - * @return Menu|null |
|
60 | - */ |
|
61 | - public function getChartMenu(Individual $individual) { |
|
62 | - return new Menu( |
|
63 | - $this->getTitle(), |
|
64 | - 'pedigree.php?rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), |
|
65 | - 'menu-chart-pedigree', |
|
66 | - array('rel' => 'nofollow') |
|
67 | - ); |
|
68 | - } |
|
56 | + /** |
|
57 | + * Return a menu item for this chart. |
|
58 | + * |
|
59 | + * @return Menu|null |
|
60 | + */ |
|
61 | + public function getChartMenu(Individual $individual) { |
|
62 | + return new Menu( |
|
63 | + $this->getTitle(), |
|
64 | + 'pedigree.php?rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), |
|
65 | + 'menu-chart-pedigree', |
|
66 | + array('rel' => 'nofollow') |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Return a menu item for this chart - for use in individual boxes. |
|
72 | - * |
|
73 | - * @return Menu|null |
|
74 | - */ |
|
75 | - public function getBoxChartMenu(Individual $individual) { |
|
76 | - return $this->getChartMenu($individual); |
|
77 | - } |
|
70 | + /** |
|
71 | + * Return a menu item for this chart - for use in individual boxes. |
|
72 | + * |
|
73 | + * @return Menu|null |
|
74 | + */ |
|
75 | + public function getBoxChartMenu(Individual $individual) { |
|
76 | + return $this->getChartMenu($individual); |
|
77 | + } |
|
78 | 78 | } |
@@ -23,13 +23,15 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * Class PedigreeChartModule |
25 | 25 | */ |
26 | -class PedigreeChartModule extends AbstractModule implements ModuleChartInterface { |
|
26 | +class PedigreeChartModule extends AbstractModule implements ModuleChartInterface |
|
27 | +{ |
|
27 | 28 | /** |
28 | 29 | * How should this module be labelled on tabs, menus, etc.? |
29 | 30 | * |
30 | 31 | * @return string |
31 | 32 | */ |
32 | - public function getTitle() { |
|
33 | + public function getTitle() |
|
34 | + { |
|
33 | 35 | return /* I18N: Name of a module/chart */ I18N::translate('Pedigree'); |
34 | 36 | } |
35 | 37 | |
@@ -38,7 +40,8 @@ discard block |
||
38 | 40 | * |
39 | 41 | * @return string |
40 | 42 | */ |
41 | - public function getDescription() { |
|
43 | + public function getDescription() |
|
44 | + { |
|
42 | 45 | return /* I18N: Description of the “PedigreeChart” module */ I18N::translate('A chart of an individual’s ancestors, formatted as a tree.'); |
43 | 46 | } |
44 | 47 | |
@@ -49,7 +52,8 @@ discard block |
||
49 | 52 | * |
50 | 53 | * @return int |
51 | 54 | */ |
52 | - public function defaultAccessLevel() { |
|
55 | + public function defaultAccessLevel() |
|
56 | + { |
|
53 | 57 | return Auth::PRIV_PRIVATE; |
54 | 58 | } |
55 | 59 | |
@@ -58,7 +62,8 @@ discard block |
||
58 | 62 | * |
59 | 63 | * @return Menu|null |
60 | 64 | */ |
61 | - public function getChartMenu(Individual $individual) { |
|
65 | + public function getChartMenu(Individual $individual) |
|
66 | + { |
|
62 | 67 | return new Menu( |
63 | 68 | $this->getTitle(), |
64 | 69 | 'pedigree.php?rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), |
@@ -72,7 +77,8 @@ discard block |
||
72 | 77 | * |
73 | 78 | * @return Menu|null |
74 | 79 | */ |
75 | - public function getBoxChartMenu(Individual $individual) { |
|
80 | + public function getBoxChartMenu(Individual $individual) |
|
81 | + { |
|
76 | 82 | return $this->getChartMenu($individual); |
77 | 83 | } |
78 | 84 | } |
@@ -35,158 +35,158 @@ discard block |
||
35 | 35 | * Class BatchUpdateModule |
36 | 36 | */ |
37 | 37 | class BatchUpdateModule extends AbstractModule implements ModuleConfigInterface { |
38 | - /** @var string Form parameter: chosen plugin*/ |
|
39 | - private $plugin; |
|
40 | - |
|
41 | - /** @var string Form parameter: record to update */ |
|
42 | - private $xref; |
|
43 | - |
|
44 | - /** @var string Form parameter: how to update record */ |
|
45 | - private $action; |
|
46 | - |
|
47 | - /** @var string Form parameter: additional details for $action */ |
|
48 | - private $data; |
|
49 | - |
|
50 | - /** @var BatchUpdateBasePlugin[] All available plugins */ |
|
51 | - private $plugins; |
|
52 | - |
|
53 | - /** @var BatchUpdateBasePlugin The current plugin */ |
|
54 | - private $PLUGIN; |
|
55 | - |
|
56 | - /** @var string[] n array of all xrefs that might need to be updated */ |
|
57 | - private $all_xrefs; |
|
58 | - |
|
59 | - /** @var string The previous xref to process */ |
|
60 | - private $prev_xref; |
|
61 | - |
|
62 | - /** @var String The current xref being process */ |
|
63 | - private $curr_xref; |
|
64 | - |
|
65 | - /** @var string The next xref to process */ |
|
66 | - private $next_xref; |
|
67 | - |
|
68 | - /** @var GedcomRecord The record corresponding to $curr_xref */ |
|
69 | - private $record; |
|
70 | - |
|
71 | - /** |
|
72 | - * How should this module be labelled on tabs, menus, etc.? |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function getTitle() { |
|
77 | - return /* I18N: Name of a module */ I18N::translate('Batch update'); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * A sentence describing what this module does. |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function getDescription() { |
|
86 | - return /* I18N: Description of the “Batch update” module */ I18N::translate('Apply automatic corrections to your genealogy data.'); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * This is a general purpose hook, allowing modules to respond to routes |
|
91 | - * of the form module.php?mod=FOO&mod_action=BAR |
|
92 | - * |
|
93 | - * @param string $mod_action |
|
94 | - */ |
|
95 | - public function modAction($mod_action) { |
|
96 | - switch ($mod_action) { |
|
97 | - case 'admin_batch_update': |
|
98 | - echo $this->main(); |
|
99 | - break; |
|
100 | - |
|
101 | - default: |
|
102 | - http_response_code(404); |
|
103 | - break; |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Main entry point |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - private function main() { |
|
113 | - global $WT_TREE; |
|
114 | - |
|
115 | - $this->plugins = $this->getPluginList(); // List of available plugins |
|
116 | - $this->plugin = Filter::get('plugin'); // User parameters |
|
117 | - $this->xref = Filter::get('xref', WT_REGEX_XREF); |
|
118 | - $this->action = Filter::get('action'); |
|
119 | - $this->data = Filter::get('data'); |
|
120 | - |
|
121 | - // Don't do any processing until a plugin is chosen. |
|
122 | - if ($this->plugin && array_key_exists($this->plugin, $this->plugins)) { |
|
123 | - $this->PLUGIN = new $this->plugin; |
|
124 | - $this->PLUGIN->getOptions(); |
|
125 | - $this->getAllXrefs(); |
|
126 | - |
|
127 | - switch ($this->action) { |
|
128 | - case 'update': |
|
129 | - $record = self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]); |
|
130 | - if ($this->PLUGIN->doesRecordNeedUpdate($this->xref, $record)) { |
|
131 | - $newrecord = $this->PLUGIN->updateRecord($this->xref, $record); |
|
132 | - if ($newrecord != $record) { |
|
133 | - if ($newrecord) { |
|
134 | - GedcomRecord::getInstance($this->xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
135 | - } else { |
|
136 | - GedcomRecord::getInstance($this->xref, $WT_TREE)->deleteRecord(); |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - $this->xref = $this->findNextXref($this->xref); |
|
141 | - break; |
|
142 | - case 'update_all': |
|
143 | - foreach ($this->all_xrefs as $xref => $type) { |
|
144 | - $record = self::getLatestRecord($xref, $type); |
|
145 | - if ($this->PLUGIN->doesRecordNeedUpdate($xref, $record)) { |
|
146 | - $newrecord = $this->PLUGIN->updateRecord($xref, $record); |
|
147 | - if ($newrecord != $record) { |
|
148 | - if ($newrecord) { |
|
149 | - GedcomRecord::getInstance($xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
150 | - } else { |
|
151 | - GedcomRecord::getInstance($xref, $WT_TREE)->deleteRecord(); |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - } |
|
156 | - $this->xref = ''; |
|
157 | - break; |
|
158 | - } |
|
159 | - |
|
160 | - // Make sure that our requested record really does need updating. |
|
161 | - // It may have been updated in another session, or may not have |
|
162 | - // been specified at all. |
|
163 | - if (array_key_exists($this->xref, $this->all_xrefs) && |
|
164 | - $this->PLUGIN->doesRecordNeedUpdate($this->xref, self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]))) { |
|
165 | - $this->curr_xref = $this->xref; |
|
166 | - } |
|
167 | - // The requested record doesn't need updating - find one that does |
|
168 | - if (!$this->curr_xref) { |
|
169 | - $this->curr_xref = $this->findNextXref($this->xref); |
|
170 | - } |
|
171 | - if (!$this->curr_xref) { |
|
172 | - $this->curr_xref = $this->findPrevXref($this->xref); |
|
173 | - } |
|
174 | - // If we've found a record to update, get details and look for the next/prev |
|
175 | - if ($this->curr_xref) { |
|
176 | - $this->prev_xref = $this->findPrevXref($this->curr_xref); |
|
177 | - $this->next_xref = $this->findNextXref($this->curr_xref); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - // HTML common to all pages |
|
182 | - $controller = new PageController; |
|
183 | - $controller |
|
184 | - ->setPageTitle(I18N::translate('Batch update')) |
|
185 | - ->restrictAccess(Auth::isAdmin()) |
|
186 | - ->pageHeader(); |
|
187 | - |
|
188 | - echo $this->getJavascript(); |
|
189 | - ?> |
|
38 | + /** @var string Form parameter: chosen plugin*/ |
|
39 | + private $plugin; |
|
40 | + |
|
41 | + /** @var string Form parameter: record to update */ |
|
42 | + private $xref; |
|
43 | + |
|
44 | + /** @var string Form parameter: how to update record */ |
|
45 | + private $action; |
|
46 | + |
|
47 | + /** @var string Form parameter: additional details for $action */ |
|
48 | + private $data; |
|
49 | + |
|
50 | + /** @var BatchUpdateBasePlugin[] All available plugins */ |
|
51 | + private $plugins; |
|
52 | + |
|
53 | + /** @var BatchUpdateBasePlugin The current plugin */ |
|
54 | + private $PLUGIN; |
|
55 | + |
|
56 | + /** @var string[] n array of all xrefs that might need to be updated */ |
|
57 | + private $all_xrefs; |
|
58 | + |
|
59 | + /** @var string The previous xref to process */ |
|
60 | + private $prev_xref; |
|
61 | + |
|
62 | + /** @var String The current xref being process */ |
|
63 | + private $curr_xref; |
|
64 | + |
|
65 | + /** @var string The next xref to process */ |
|
66 | + private $next_xref; |
|
67 | + |
|
68 | + /** @var GedcomRecord The record corresponding to $curr_xref */ |
|
69 | + private $record; |
|
70 | + |
|
71 | + /** |
|
72 | + * How should this module be labelled on tabs, menus, etc.? |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function getTitle() { |
|
77 | + return /* I18N: Name of a module */ I18N::translate('Batch update'); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * A sentence describing what this module does. |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function getDescription() { |
|
86 | + return /* I18N: Description of the “Batch update” module */ I18N::translate('Apply automatic corrections to your genealogy data.'); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * This is a general purpose hook, allowing modules to respond to routes |
|
91 | + * of the form module.php?mod=FOO&mod_action=BAR |
|
92 | + * |
|
93 | + * @param string $mod_action |
|
94 | + */ |
|
95 | + public function modAction($mod_action) { |
|
96 | + switch ($mod_action) { |
|
97 | + case 'admin_batch_update': |
|
98 | + echo $this->main(); |
|
99 | + break; |
|
100 | + |
|
101 | + default: |
|
102 | + http_response_code(404); |
|
103 | + break; |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Main entry point |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + private function main() { |
|
113 | + global $WT_TREE; |
|
114 | + |
|
115 | + $this->plugins = $this->getPluginList(); // List of available plugins |
|
116 | + $this->plugin = Filter::get('plugin'); // User parameters |
|
117 | + $this->xref = Filter::get('xref', WT_REGEX_XREF); |
|
118 | + $this->action = Filter::get('action'); |
|
119 | + $this->data = Filter::get('data'); |
|
120 | + |
|
121 | + // Don't do any processing until a plugin is chosen. |
|
122 | + if ($this->plugin && array_key_exists($this->plugin, $this->plugins)) { |
|
123 | + $this->PLUGIN = new $this->plugin; |
|
124 | + $this->PLUGIN->getOptions(); |
|
125 | + $this->getAllXrefs(); |
|
126 | + |
|
127 | + switch ($this->action) { |
|
128 | + case 'update': |
|
129 | + $record = self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]); |
|
130 | + if ($this->PLUGIN->doesRecordNeedUpdate($this->xref, $record)) { |
|
131 | + $newrecord = $this->PLUGIN->updateRecord($this->xref, $record); |
|
132 | + if ($newrecord != $record) { |
|
133 | + if ($newrecord) { |
|
134 | + GedcomRecord::getInstance($this->xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
135 | + } else { |
|
136 | + GedcomRecord::getInstance($this->xref, $WT_TREE)->deleteRecord(); |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | + $this->xref = $this->findNextXref($this->xref); |
|
141 | + break; |
|
142 | + case 'update_all': |
|
143 | + foreach ($this->all_xrefs as $xref => $type) { |
|
144 | + $record = self::getLatestRecord($xref, $type); |
|
145 | + if ($this->PLUGIN->doesRecordNeedUpdate($xref, $record)) { |
|
146 | + $newrecord = $this->PLUGIN->updateRecord($xref, $record); |
|
147 | + if ($newrecord != $record) { |
|
148 | + if ($newrecord) { |
|
149 | + GedcomRecord::getInstance($xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
150 | + } else { |
|
151 | + GedcomRecord::getInstance($xref, $WT_TREE)->deleteRecord(); |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + } |
|
156 | + $this->xref = ''; |
|
157 | + break; |
|
158 | + } |
|
159 | + |
|
160 | + // Make sure that our requested record really does need updating. |
|
161 | + // It may have been updated in another session, or may not have |
|
162 | + // been specified at all. |
|
163 | + if (array_key_exists($this->xref, $this->all_xrefs) && |
|
164 | + $this->PLUGIN->doesRecordNeedUpdate($this->xref, self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]))) { |
|
165 | + $this->curr_xref = $this->xref; |
|
166 | + } |
|
167 | + // The requested record doesn't need updating - find one that does |
|
168 | + if (!$this->curr_xref) { |
|
169 | + $this->curr_xref = $this->findNextXref($this->xref); |
|
170 | + } |
|
171 | + if (!$this->curr_xref) { |
|
172 | + $this->curr_xref = $this->findPrevXref($this->xref); |
|
173 | + } |
|
174 | + // If we've found a record to update, get details and look for the next/prev |
|
175 | + if ($this->curr_xref) { |
|
176 | + $this->prev_xref = $this->findPrevXref($this->curr_xref); |
|
177 | + $this->next_xref = $this->findNextXref($this->curr_xref); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + // HTML common to all pages |
|
182 | + $controller = new PageController; |
|
183 | + $controller |
|
184 | + ->setPageTitle(I18N::translate('Batch update')) |
|
185 | + ->restrictAccess(Auth::isAdmin()) |
|
186 | + ->pageHeader(); |
|
187 | + |
|
188 | + echo $this->getJavascript(); |
|
189 | + ?> |
|
190 | 190 | <ol class="breadcrumb small"> |
191 | 191 | <li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li> |
192 | 192 | <li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li> |
@@ -261,181 +261,181 @@ discard block |
||
261 | 261 | <?php endif; ?> |
262 | 262 | </form> |
263 | 263 | <?php |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Find the next record that needs to be updated. |
|
268 | - * |
|
269 | - * @param string $xref |
|
270 | - * |
|
271 | - * @return string|null |
|
272 | - */ |
|
273 | - private function findNextXref($xref) { |
|
274 | - foreach (array_keys($this->all_xrefs) as $key) { |
|
275 | - if ($key > $xref) { |
|
276 | - $record = self::getLatestRecord($key, $this->all_xrefs[$key]); |
|
277 | - if ($this->PLUGIN->doesRecordNeedUpdate($key, $record)) { |
|
278 | - return $key; |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - return null; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Find the previous record that needs to be updated. |
|
288 | - * |
|
289 | - * @param string $xref |
|
290 | - * |
|
291 | - * @return string|null |
|
292 | - */ |
|
293 | - private function findPrevXref($xref) { |
|
294 | - foreach (array_reverse(array_keys($this->all_xrefs)) as $key) { |
|
295 | - if ($key < $xref) { |
|
296 | - $record = self::getLatestRecord($key, $this->all_xrefs[$key]); |
|
297 | - if ($this->PLUGIN->doesRecordNeedUpdate($key, $record)) { |
|
298 | - return $key; |
|
299 | - } |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - return null; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Generate a list of all XREFs. |
|
308 | - */ |
|
309 | - private function getAllXrefs() { |
|
310 | - global $WT_TREE; |
|
311 | - |
|
312 | - $sql = array(); |
|
313 | - $vars = array(); |
|
314 | - foreach ($this->PLUGIN->getRecordTypesToUpdate() as $type) { |
|
315 | - switch ($type) { |
|
316 | - case 'INDI': |
|
317 | - $sql[] = "SELECT i_id, 'INDI' FROM `##individuals` WHERE i_file=?"; |
|
318 | - $vars[] = $WT_TREE->getTreeId(); |
|
319 | - break; |
|
320 | - case 'FAM': |
|
321 | - $sql[] = "SELECT f_id, 'FAM' FROM `##families` WHERE f_file=?"; |
|
322 | - $vars[] = $WT_TREE->getTreeId(); |
|
323 | - break; |
|
324 | - case 'SOUR': |
|
325 | - $sql[] = "SELECT s_id, 'SOUR' FROM `##sources` WHERE s_file=?"; |
|
326 | - $vars[] = $WT_TREE->getTreeId(); |
|
327 | - break; |
|
328 | - case 'OBJE': |
|
329 | - $sql[] = "SELECT m_id, 'OBJE' FROM `##media` WHERE m_file=?"; |
|
330 | - $vars[] = $WT_TREE->getTreeId(); |
|
331 | - break; |
|
332 | - default: |
|
333 | - $sql[] = "SELECT o_id, ? FROM `##other` WHERE o_type=? AND o_file=?"; |
|
334 | - $vars[] = $type; |
|
335 | - $vars[] = $type; |
|
336 | - $vars[] = $WT_TREE->getTreeId(); |
|
337 | - break; |
|
338 | - } |
|
339 | - } |
|
340 | - $this->all_xrefs = |
|
341 | - Database::prepare(implode(' UNION ', $sql) . ' ORDER BY 1 ASC') |
|
342 | - ->execute($vars) |
|
343 | - ->fetchAssoc(); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Scan the plugin folder for a list of plugins |
|
348 | - * |
|
349 | - * @return BatchUpdateBasePlugin[] |
|
350 | - */ |
|
351 | - private function getPluginList() { |
|
352 | - $plugins = array(); |
|
353 | - $dir_handle = opendir(__DIR__ . '/BatchUpdate'); |
|
354 | - while (($file = readdir($dir_handle)) !== false) { |
|
355 | - if (substr($file, -10) == 'Plugin.php' && $file !== 'BatchUpdateBasePlugin.php') { |
|
356 | - $class = '\Fisharebest\Webtrees\Module\BatchUpdate\\' . basename($file, '.php'); |
|
357 | - $plugins[$class] = new $class; |
|
358 | - } |
|
359 | - } |
|
360 | - closedir($dir_handle); |
|
361 | - |
|
362 | - return $plugins; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Javascript that gets included on every page |
|
367 | - * |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - private function getJavascript() { |
|
371 | - return |
|
372 | - '<script>' . |
|
373 | - 'function reset_reload() {' . |
|
374 | - ' var bu_form=document.getElementById("batch_update_form");' . |
|
375 | - ' bu_form.xref.value="";' . |
|
376 | - ' bu_form.action.value="";' . |
|
377 | - ' bu_form.data.value="";' . |
|
378 | - ' bu_form.submit();' . |
|
379 | - '}</script>'; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Create a submit button for our form |
|
384 | - * |
|
385 | - * @param string $text |
|
386 | - * @param string $xref |
|
387 | - * @param string $action |
|
388 | - * @param string $data |
|
389 | - * |
|
390 | - * @return string |
|
391 | - */ |
|
392 | - public static function createSubmitButton($text, $xref, $action = '', $data = '') { |
|
393 | - return |
|
394 | - '<input class="btn btn-primary" type="submit" value="' . $text . '" onclick="' . |
|
395 | - 'this.form.xref.value=\'' . Filter::escapeHtml($xref) . '\';' . |
|
396 | - 'this.form.action.value=\'' . Filter::escapeHtml($action) . '\';' . |
|
397 | - 'this.form.data.value=\'' . Filter::escapeHtml($data) . '\';' . |
|
398 | - 'return true;"' . |
|
399 | - ($xref ? '' : ' disabled') . '>'; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Get the current view of a record, allowing for pending changes |
|
404 | - * |
|
405 | - * @param string $xref |
|
406 | - * @param string $type |
|
407 | - * |
|
408 | - * @return string |
|
409 | - */ |
|
410 | - public static function getLatestRecord($xref, $type) { |
|
411 | - global $WT_TREE; |
|
412 | - |
|
413 | - switch ($type) { |
|
414 | - case 'INDI': |
|
415 | - return Individual::getInstance($xref, $WT_TREE)->getGedcom(); |
|
416 | - case 'FAM': |
|
417 | - return Family::getInstance($xref, $WT_TREE)->getGedcom(); |
|
418 | - case 'SOUR': |
|
419 | - return Source::getInstance($xref, $WT_TREE)->getGedcom(); |
|
420 | - case 'REPO': |
|
421 | - return Repository::getInstance($xref, $WT_TREE)->getGedcom(); |
|
422 | - case 'OBJE': |
|
423 | - return Media::getInstance($xref, $WT_TREE)->getGedcom(); |
|
424 | - case 'NOTE': |
|
425 | - return Note::getInstance($xref, $WT_TREE)->getGedcom(); |
|
426 | - default: |
|
427 | - return GedcomRecord::getInstance($xref, $WT_TREE)->getGedcom(); |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * The URL to a page where the user can modify the configuration of this module. |
|
433 | - * These links are displayed in the admin page menu. |
|
434 | - * |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - public function getConfigLink() { |
|
438 | - return 'module.php?mod=' . $this->getName() . '&mod_action=admin_batch_update'; |
|
439 | - } |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Find the next record that needs to be updated. |
|
268 | + * |
|
269 | + * @param string $xref |
|
270 | + * |
|
271 | + * @return string|null |
|
272 | + */ |
|
273 | + private function findNextXref($xref) { |
|
274 | + foreach (array_keys($this->all_xrefs) as $key) { |
|
275 | + if ($key > $xref) { |
|
276 | + $record = self::getLatestRecord($key, $this->all_xrefs[$key]); |
|
277 | + if ($this->PLUGIN->doesRecordNeedUpdate($key, $record)) { |
|
278 | + return $key; |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + return null; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Find the previous record that needs to be updated. |
|
288 | + * |
|
289 | + * @param string $xref |
|
290 | + * |
|
291 | + * @return string|null |
|
292 | + */ |
|
293 | + private function findPrevXref($xref) { |
|
294 | + foreach (array_reverse(array_keys($this->all_xrefs)) as $key) { |
|
295 | + if ($key < $xref) { |
|
296 | + $record = self::getLatestRecord($key, $this->all_xrefs[$key]); |
|
297 | + if ($this->PLUGIN->doesRecordNeedUpdate($key, $record)) { |
|
298 | + return $key; |
|
299 | + } |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + return null; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Generate a list of all XREFs. |
|
308 | + */ |
|
309 | + private function getAllXrefs() { |
|
310 | + global $WT_TREE; |
|
311 | + |
|
312 | + $sql = array(); |
|
313 | + $vars = array(); |
|
314 | + foreach ($this->PLUGIN->getRecordTypesToUpdate() as $type) { |
|
315 | + switch ($type) { |
|
316 | + case 'INDI': |
|
317 | + $sql[] = "SELECT i_id, 'INDI' FROM `##individuals` WHERE i_file=?"; |
|
318 | + $vars[] = $WT_TREE->getTreeId(); |
|
319 | + break; |
|
320 | + case 'FAM': |
|
321 | + $sql[] = "SELECT f_id, 'FAM' FROM `##families` WHERE f_file=?"; |
|
322 | + $vars[] = $WT_TREE->getTreeId(); |
|
323 | + break; |
|
324 | + case 'SOUR': |
|
325 | + $sql[] = "SELECT s_id, 'SOUR' FROM `##sources` WHERE s_file=?"; |
|
326 | + $vars[] = $WT_TREE->getTreeId(); |
|
327 | + break; |
|
328 | + case 'OBJE': |
|
329 | + $sql[] = "SELECT m_id, 'OBJE' FROM `##media` WHERE m_file=?"; |
|
330 | + $vars[] = $WT_TREE->getTreeId(); |
|
331 | + break; |
|
332 | + default: |
|
333 | + $sql[] = "SELECT o_id, ? FROM `##other` WHERE o_type=? AND o_file=?"; |
|
334 | + $vars[] = $type; |
|
335 | + $vars[] = $type; |
|
336 | + $vars[] = $WT_TREE->getTreeId(); |
|
337 | + break; |
|
338 | + } |
|
339 | + } |
|
340 | + $this->all_xrefs = |
|
341 | + Database::prepare(implode(' UNION ', $sql) . ' ORDER BY 1 ASC') |
|
342 | + ->execute($vars) |
|
343 | + ->fetchAssoc(); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Scan the plugin folder for a list of plugins |
|
348 | + * |
|
349 | + * @return BatchUpdateBasePlugin[] |
|
350 | + */ |
|
351 | + private function getPluginList() { |
|
352 | + $plugins = array(); |
|
353 | + $dir_handle = opendir(__DIR__ . '/BatchUpdate'); |
|
354 | + while (($file = readdir($dir_handle)) !== false) { |
|
355 | + if (substr($file, -10) == 'Plugin.php' && $file !== 'BatchUpdateBasePlugin.php') { |
|
356 | + $class = '\Fisharebest\Webtrees\Module\BatchUpdate\\' . basename($file, '.php'); |
|
357 | + $plugins[$class] = new $class; |
|
358 | + } |
|
359 | + } |
|
360 | + closedir($dir_handle); |
|
361 | + |
|
362 | + return $plugins; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Javascript that gets included on every page |
|
367 | + * |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + private function getJavascript() { |
|
371 | + return |
|
372 | + '<script>' . |
|
373 | + 'function reset_reload() {' . |
|
374 | + ' var bu_form=document.getElementById("batch_update_form");' . |
|
375 | + ' bu_form.xref.value="";' . |
|
376 | + ' bu_form.action.value="";' . |
|
377 | + ' bu_form.data.value="";' . |
|
378 | + ' bu_form.submit();' . |
|
379 | + '}</script>'; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Create a submit button for our form |
|
384 | + * |
|
385 | + * @param string $text |
|
386 | + * @param string $xref |
|
387 | + * @param string $action |
|
388 | + * @param string $data |
|
389 | + * |
|
390 | + * @return string |
|
391 | + */ |
|
392 | + public static function createSubmitButton($text, $xref, $action = '', $data = '') { |
|
393 | + return |
|
394 | + '<input class="btn btn-primary" type="submit" value="' . $text . '" onclick="' . |
|
395 | + 'this.form.xref.value=\'' . Filter::escapeHtml($xref) . '\';' . |
|
396 | + 'this.form.action.value=\'' . Filter::escapeHtml($action) . '\';' . |
|
397 | + 'this.form.data.value=\'' . Filter::escapeHtml($data) . '\';' . |
|
398 | + 'return true;"' . |
|
399 | + ($xref ? '' : ' disabled') . '>'; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Get the current view of a record, allowing for pending changes |
|
404 | + * |
|
405 | + * @param string $xref |
|
406 | + * @param string $type |
|
407 | + * |
|
408 | + * @return string |
|
409 | + */ |
|
410 | + public static function getLatestRecord($xref, $type) { |
|
411 | + global $WT_TREE; |
|
412 | + |
|
413 | + switch ($type) { |
|
414 | + case 'INDI': |
|
415 | + return Individual::getInstance($xref, $WT_TREE)->getGedcom(); |
|
416 | + case 'FAM': |
|
417 | + return Family::getInstance($xref, $WT_TREE)->getGedcom(); |
|
418 | + case 'SOUR': |
|
419 | + return Source::getInstance($xref, $WT_TREE)->getGedcom(); |
|
420 | + case 'REPO': |
|
421 | + return Repository::getInstance($xref, $WT_TREE)->getGedcom(); |
|
422 | + case 'OBJE': |
|
423 | + return Media::getInstance($xref, $WT_TREE)->getGedcom(); |
|
424 | + case 'NOTE': |
|
425 | + return Note::getInstance($xref, $WT_TREE)->getGedcom(); |
|
426 | + default: |
|
427 | + return GedcomRecord::getInstance($xref, $WT_TREE)->getGedcom(); |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * The URL to a page where the user can modify the configuration of this module. |
|
433 | + * These links are displayed in the admin page menu. |
|
434 | + * |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + public function getConfigLink() { |
|
438 | + return 'module.php?mod=' . $this->getName() . '&mod_action=admin_batch_update'; |
|
439 | + } |
|
440 | 440 | |
441 | 441 | } |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function modAction($mod_action) { |
96 | 96 | switch ($mod_action) { |
97 | - case 'admin_batch_update': |
|
98 | - echo $this->main(); |
|
99 | - break; |
|
97 | + case 'admin_batch_update': |
|
98 | + echo $this->main(); |
|
99 | + break; |
|
100 | 100 | |
101 | - default: |
|
102 | - http_response_code(404); |
|
103 | - break; |
|
101 | + default: |
|
102 | + http_response_code(404); |
|
103 | + break; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -125,36 +125,36 @@ discard block |
||
125 | 125 | $this->getAllXrefs(); |
126 | 126 | |
127 | 127 | switch ($this->action) { |
128 | - case 'update': |
|
129 | - $record = self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]); |
|
130 | - if ($this->PLUGIN->doesRecordNeedUpdate($this->xref, $record)) { |
|
131 | - $newrecord = $this->PLUGIN->updateRecord($this->xref, $record); |
|
132 | - if ($newrecord != $record) { |
|
133 | - if ($newrecord) { |
|
134 | - GedcomRecord::getInstance($this->xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
135 | - } else { |
|
136 | - GedcomRecord::getInstance($this->xref, $WT_TREE)->deleteRecord(); |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - $this->xref = $this->findNextXref($this->xref); |
|
141 | - break; |
|
142 | - case 'update_all': |
|
143 | - foreach ($this->all_xrefs as $xref => $type) { |
|
144 | - $record = self::getLatestRecord($xref, $type); |
|
145 | - if ($this->PLUGIN->doesRecordNeedUpdate($xref, $record)) { |
|
146 | - $newrecord = $this->PLUGIN->updateRecord($xref, $record); |
|
147 | - if ($newrecord != $record) { |
|
148 | - if ($newrecord) { |
|
149 | - GedcomRecord::getInstance($xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
150 | - } else { |
|
151 | - GedcomRecord::getInstance($xref, $WT_TREE)->deleteRecord(); |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - } |
|
156 | - $this->xref = ''; |
|
157 | - break; |
|
128 | + case 'update': |
|
129 | + $record = self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]); |
|
130 | + if ($this->PLUGIN->doesRecordNeedUpdate($this->xref, $record)) { |
|
131 | + $newrecord = $this->PLUGIN->updateRecord($this->xref, $record); |
|
132 | + if ($newrecord != $record) { |
|
133 | + if ($newrecord) { |
|
134 | + GedcomRecord::getInstance($this->xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
135 | + } else { |
|
136 | + GedcomRecord::getInstance($this->xref, $WT_TREE)->deleteRecord(); |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | + $this->xref = $this->findNextXref($this->xref); |
|
141 | + break; |
|
142 | + case 'update_all': |
|
143 | + foreach ($this->all_xrefs as $xref => $type) { |
|
144 | + $record = self::getLatestRecord($xref, $type); |
|
145 | + if ($this->PLUGIN->doesRecordNeedUpdate($xref, $record)) { |
|
146 | + $newrecord = $this->PLUGIN->updateRecord($xref, $record); |
|
147 | + if ($newrecord != $record) { |
|
148 | + if ($newrecord) { |
|
149 | + GedcomRecord::getInstance($xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
|
150 | + } else { |
|
151 | + GedcomRecord::getInstance($xref, $WT_TREE)->deleteRecord(); |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + } |
|
156 | + $this->xref = ''; |
|
157 | + break; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Make sure that our requested record really does need updating. |
@@ -313,28 +313,28 @@ discard block |
||
313 | 313 | $vars = array(); |
314 | 314 | foreach ($this->PLUGIN->getRecordTypesToUpdate() as $type) { |
315 | 315 | switch ($type) { |
316 | - case 'INDI': |
|
317 | - $sql[] = "SELECT i_id, 'INDI' FROM `##individuals` WHERE i_file=?"; |
|
318 | - $vars[] = $WT_TREE->getTreeId(); |
|
319 | - break; |
|
320 | - case 'FAM': |
|
321 | - $sql[] = "SELECT f_id, 'FAM' FROM `##families` WHERE f_file=?"; |
|
322 | - $vars[] = $WT_TREE->getTreeId(); |
|
323 | - break; |
|
324 | - case 'SOUR': |
|
325 | - $sql[] = "SELECT s_id, 'SOUR' FROM `##sources` WHERE s_file=?"; |
|
326 | - $vars[] = $WT_TREE->getTreeId(); |
|
327 | - break; |
|
328 | - case 'OBJE': |
|
329 | - $sql[] = "SELECT m_id, 'OBJE' FROM `##media` WHERE m_file=?"; |
|
330 | - $vars[] = $WT_TREE->getTreeId(); |
|
331 | - break; |
|
332 | - default: |
|
333 | - $sql[] = "SELECT o_id, ? FROM `##other` WHERE o_type=? AND o_file=?"; |
|
334 | - $vars[] = $type; |
|
335 | - $vars[] = $type; |
|
336 | - $vars[] = $WT_TREE->getTreeId(); |
|
337 | - break; |
|
316 | + case 'INDI': |
|
317 | + $sql[] = "SELECT i_id, 'INDI' FROM `##individuals` WHERE i_file=?"; |
|
318 | + $vars[] = $WT_TREE->getTreeId(); |
|
319 | + break; |
|
320 | + case 'FAM': |
|
321 | + $sql[] = "SELECT f_id, 'FAM' FROM `##families` WHERE f_file=?"; |
|
322 | + $vars[] = $WT_TREE->getTreeId(); |
|
323 | + break; |
|
324 | + case 'SOUR': |
|
325 | + $sql[] = "SELECT s_id, 'SOUR' FROM `##sources` WHERE s_file=?"; |
|
326 | + $vars[] = $WT_TREE->getTreeId(); |
|
327 | + break; |
|
328 | + case 'OBJE': |
|
329 | + $sql[] = "SELECT m_id, 'OBJE' FROM `##media` WHERE m_file=?"; |
|
330 | + $vars[] = $WT_TREE->getTreeId(); |
|
331 | + break; |
|
332 | + default: |
|
333 | + $sql[] = "SELECT o_id, ? FROM `##other` WHERE o_type=? AND o_file=?"; |
|
334 | + $vars[] = $type; |
|
335 | + $vars[] = $type; |
|
336 | + $vars[] = $WT_TREE->getTreeId(); |
|
337 | + break; |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | $this->all_xrefs = |
@@ -411,20 +411,20 @@ discard block |
||
411 | 411 | global $WT_TREE; |
412 | 412 | |
413 | 413 | switch ($type) { |
414 | - case 'INDI': |
|
415 | - return Individual::getInstance($xref, $WT_TREE)->getGedcom(); |
|
416 | - case 'FAM': |
|
417 | - return Family::getInstance($xref, $WT_TREE)->getGedcom(); |
|
418 | - case 'SOUR': |
|
419 | - return Source::getInstance($xref, $WT_TREE)->getGedcom(); |
|
420 | - case 'REPO': |
|
421 | - return Repository::getInstance($xref, $WT_TREE)->getGedcom(); |
|
422 | - case 'OBJE': |
|
423 | - return Media::getInstance($xref, $WT_TREE)->getGedcom(); |
|
424 | - case 'NOTE': |
|
425 | - return Note::getInstance($xref, $WT_TREE)->getGedcom(); |
|
426 | - default: |
|
427 | - return GedcomRecord::getInstance($xref, $WT_TREE)->getGedcom(); |
|
414 | + case 'INDI': |
|
415 | + return Individual::getInstance($xref, $WT_TREE)->getGedcom(); |
|
416 | + case 'FAM': |
|
417 | + return Family::getInstance($xref, $WT_TREE)->getGedcom(); |
|
418 | + case 'SOUR': |
|
419 | + return Source::getInstance($xref, $WT_TREE)->getGedcom(); |
|
420 | + case 'REPO': |
|
421 | + return Repository::getInstance($xref, $WT_TREE)->getGedcom(); |
|
422 | + case 'OBJE': |
|
423 | + return Media::getInstance($xref, $WT_TREE)->getGedcom(); |
|
424 | + case 'NOTE': |
|
425 | + return Note::getInstance($xref, $WT_TREE)->getGedcom(); |
|
426 | + default: |
|
427 | + return GedcomRecord::getInstance($xref, $WT_TREE)->getGedcom(); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * Class BatchUpdateModule |
36 | 36 | */ |
37 | -class BatchUpdateModule extends AbstractModule implements ModuleConfigInterface { |
|
37 | +class BatchUpdateModule extends AbstractModule implements ModuleConfigInterface |
|
38 | +{ |
|
38 | 39 | /** @var string Form parameter: chosen plugin*/ |
39 | 40 | private $plugin; |
40 | 41 | |
@@ -73,7 +74,8 @@ discard block |
||
73 | 74 | * |
74 | 75 | * @return string |
75 | 76 | */ |
76 | - public function getTitle() { |
|
77 | + public function getTitle() |
|
78 | + { |
|
77 | 79 | return /* I18N: Name of a module */ I18N::translate('Batch update'); |
78 | 80 | } |
79 | 81 | |
@@ -82,7 +84,8 @@ discard block |
||
82 | 84 | * |
83 | 85 | * @return string |
84 | 86 | */ |
85 | - public function getDescription() { |
|
87 | + public function getDescription() |
|
88 | + { |
|
86 | 89 | return /* I18N: Description of the “Batch update” module */ I18N::translate('Apply automatic corrections to your genealogy data.'); |
87 | 90 | } |
88 | 91 | |
@@ -92,7 +95,8 @@ discard block |
||
92 | 95 | * |
93 | 96 | * @param string $mod_action |
94 | 97 | */ |
95 | - public function modAction($mod_action) { |
|
98 | + public function modAction($mod_action) |
|
99 | + { |
|
96 | 100 | switch ($mod_action) { |
97 | 101 | case 'admin_batch_update': |
98 | 102 | echo $this->main(); |
@@ -109,7 +113,8 @@ discard block |
||
109 | 113 | * |
110 | 114 | * @return string |
111 | 115 | */ |
112 | - private function main() { |
|
116 | + private function main() |
|
117 | + { |
|
113 | 118 | global $WT_TREE; |
114 | 119 | |
115 | 120 | $this->plugins = $this->getPluginList(); // List of available plugins |
@@ -236,12 +241,15 @@ discard block |
||
236 | 241 | <?php // Reset - otherwise we might "undo all changes", which refreshes the ?> |
237 | 242 | <?php // page, which makes them all again! ?> |
238 | 243 | <script>reset_reload();</script> |
239 | - <?php else: ?> |
|
244 | + <?php else { |
|
245 | + : ?> |
|
240 | 246 | <hr> |
241 | 247 | <div id="batch_update2" class="col-sm-12"> |
242 | 248 | <?php if ($this->curr_xref): ?> |
243 | 249 | <?php // Create an object, so we can get the latest version of the name. ?> |
244 | - <?php $this->record = GedcomRecord::getInstance($this->curr_xref, $WT_TREE); ?> |
|
250 | + <?php $this->record = GedcomRecord::getInstance($this->curr_xref, $WT_TREE); |
|
251 | +} |
|
252 | +?> |
|
245 | 253 | <div class="form-group"> |
246 | 254 | <?php echo self::createSubmitButton(I18N::translate('previous'), $this->prev_xref) ?> |
247 | 255 | <?php echo self::createSubmitButton(I18N::translate('next'), $this->next_xref) ?> |
@@ -253,8 +261,11 @@ discard block |
||
253 | 261 | <div class="form-group"> |
254 | 262 | <?php echo implode(' ', $this->PLUGIN->getActionButtons($this->curr_xref, $this->record)); ?> |
255 | 263 | </div> |
256 | - <?php else: ?> |
|
257 | - <div class="alert alert-info"><?php echo I18N::translate('Nothing found.'); ?></div> |
|
264 | + <?php else { |
|
265 | + : ?> |
|
266 | + <div class="alert alert-info"><?php echo I18N::translate('Nothing found.'); |
|
267 | +} |
|
268 | +?></div> |
|
258 | 269 | <?php endif; ?> |
259 | 270 | </div> |
260 | 271 | <?php endif; ?> |
@@ -270,7 +281,8 @@ discard block |
||
270 | 281 | * |
271 | 282 | * @return string|null |
272 | 283 | */ |
273 | - private function findNextXref($xref) { |
|
284 | + private function findNextXref($xref) |
|
285 | + { |
|
274 | 286 | foreach (array_keys($this->all_xrefs) as $key) { |
275 | 287 | if ($key > $xref) { |
276 | 288 | $record = self::getLatestRecord($key, $this->all_xrefs[$key]); |
@@ -290,7 +302,8 @@ discard block |
||
290 | 302 | * |
291 | 303 | * @return string|null |
292 | 304 | */ |
293 | - private function findPrevXref($xref) { |
|
305 | + private function findPrevXref($xref) |
|
306 | + { |
|
294 | 307 | foreach (array_reverse(array_keys($this->all_xrefs)) as $key) { |
295 | 308 | if ($key < $xref) { |
296 | 309 | $record = self::getLatestRecord($key, $this->all_xrefs[$key]); |
@@ -306,7 +319,8 @@ discard block |
||
306 | 319 | /** |
307 | 320 | * Generate a list of all XREFs. |
308 | 321 | */ |
309 | - private function getAllXrefs() { |
|
322 | + private function getAllXrefs() |
|
323 | + { |
|
310 | 324 | global $WT_TREE; |
311 | 325 | |
312 | 326 | $sql = array(); |
@@ -348,7 +362,8 @@ discard block |
||
348 | 362 | * |
349 | 363 | * @return BatchUpdateBasePlugin[] |
350 | 364 | */ |
351 | - private function getPluginList() { |
|
365 | + private function getPluginList() |
|
366 | + { |
|
352 | 367 | $plugins = array(); |
353 | 368 | $dir_handle = opendir(__DIR__ . '/BatchUpdate'); |
354 | 369 | while (($file = readdir($dir_handle)) !== false) { |
@@ -367,7 +382,8 @@ discard block |
||
367 | 382 | * |
368 | 383 | * @return string |
369 | 384 | */ |
370 | - private function getJavascript() { |
|
385 | + private function getJavascript() |
|
386 | + { |
|
371 | 387 | return |
372 | 388 | '<script>' . |
373 | 389 | 'function reset_reload() {' . |
@@ -389,7 +405,8 @@ discard block |
||
389 | 405 | * |
390 | 406 | * @return string |
391 | 407 | */ |
392 | - public static function createSubmitButton($text, $xref, $action = '', $data = '') { |
|
408 | + public static function createSubmitButton($text, $xref, $action = '', $data = '') |
|
409 | + { |
|
393 | 410 | return |
394 | 411 | '<input class="btn btn-primary" type="submit" value="' . $text . '" onclick="' . |
395 | 412 | 'this.form.xref.value=\'' . Filter::escapeHtml($xref) . '\';' . |
@@ -407,7 +424,8 @@ discard block |
||
407 | 424 | * |
408 | 425 | * @return string |
409 | 426 | */ |
410 | - public static function getLatestRecord($xref, $type) { |
|
427 | + public static function getLatestRecord($xref, $type) |
|
428 | + { |
|
411 | 429 | global $WT_TREE; |
412 | 430 | |
413 | 431 | switch ($type) { |
@@ -434,7 +452,8 @@ discard block |
||
434 | 452 | * |
435 | 453 | * @return string |
436 | 454 | */ |
437 | - public function getConfigLink() { |
|
455 | + public function getConfigLink() |
|
456 | + { |
|
438 | 457 | return 'module.php?mod=' . $this->getName() . '&mod_action=admin_batch_update'; |
439 | 458 | } |
440 | 459 |
@@ -23,143 +23,143 @@ |
||
23 | 23 | * Class BatchUpdateMarriedNamesPlugin Batch Update plugin: add missing 2 _MARNM records |
24 | 24 | */ |
25 | 25 | class BatchUpdateMarriedNamesPlugin extends BatchUpdateBasePlugin { |
26 | - /** @var string User option: add or replace husband’s surname */ |
|
27 | - private $surname; |
|
26 | + /** @var string User option: add or replace husband’s surname */ |
|
27 | + private $surname; |
|
28 | 28 | |
29 | - /** |
|
30 | - * User-friendly name for this plugin. |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getName() { |
|
35 | - return I18N::translate('Add missing married names'); |
|
36 | - } |
|
29 | + /** |
|
30 | + * User-friendly name for this plugin. |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getName() { |
|
35 | + return I18N::translate('Add missing married names'); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Description / help-text for this plugin. |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function getDescription() { |
|
44 | - return I18N::translate('You can make it easier to search for married women by recording their married name. However not all women take their husband’s surname, so beware of introducing incorrect information into your database.'); |
|
45 | - } |
|
38 | + /** |
|
39 | + * Description / help-text for this plugin. |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function getDescription() { |
|
44 | + return I18N::translate('You can make it easier to search for married women by recording their married name. However not all women take their husband’s surname, so beware of introducing incorrect information into your database.'); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Does this record need updating? |
|
49 | - * |
|
50 | - * @param string $xref |
|
51 | - * @param string $gedrec |
|
52 | - * |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
56 | - return preg_match('/^1 SEX F/m', $gedrec) && preg_match('/^1 NAME /m', $gedrec) && self::surnamesToAdd($xref, $gedrec); |
|
57 | - } |
|
47 | + /** |
|
48 | + * Does this record need updating? |
|
49 | + * |
|
50 | + * @param string $xref |
|
51 | + * @param string $gedrec |
|
52 | + * |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function doesRecordNeedUpdate($xref, $gedrec) { |
|
56 | + return preg_match('/^1 SEX F/m', $gedrec) && preg_match('/^1 NAME /m', $gedrec) && self::surnamesToAdd($xref, $gedrec); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Apply any updates to this record |
|
61 | - * |
|
62 | - * @param string $xref |
|
63 | - * @param string $gedrec |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function updateRecord($xref, $gedrec) { |
|
68 | - global $WT_TREE; |
|
59 | + /** |
|
60 | + * Apply any updates to this record |
|
61 | + * |
|
62 | + * @param string $xref |
|
63 | + * @param string $gedrec |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function updateRecord($xref, $gedrec) { |
|
68 | + global $WT_TREE; |
|
69 | 69 | |
70 | - $SURNAME_TRADITION = $WT_TREE->getPreference('SURNAME_TRADITION'); |
|
70 | + $SURNAME_TRADITION = $WT_TREE->getPreference('SURNAME_TRADITION'); |
|
71 | 71 | |
72 | - preg_match('/^1 NAME (.*)/m', $gedrec, $match); |
|
73 | - $wife_name = $match[1]; |
|
74 | - $married_names = array(); |
|
75 | - foreach (self::surnamesToAdd($xref, $gedrec) as $surname) { |
|
76 | - switch ($this->surname) { |
|
77 | - case 'add': |
|
78 | - $married_names[] = "\n2 _MARNM " . str_replace('/', '', $wife_name) . ' /' . $surname . '/'; |
|
79 | - break; |
|
80 | - case 'replace': |
|
81 | - if ($SURNAME_TRADITION === 'polish') { |
|
82 | - $surname = preg_replace(array('/ski$/', '/cki$/', '/dzki$/'), array('ska', 'cka', 'dzka'), $surname); |
|
83 | - } |
|
84 | - $married_names[] = "\n2 _MARNM " . preg_replace('!/.*/!', '/' . $surname . '/', $wife_name); |
|
85 | - break; |
|
86 | - } |
|
87 | - } |
|
72 | + preg_match('/^1 NAME (.*)/m', $gedrec, $match); |
|
73 | + $wife_name = $match[1]; |
|
74 | + $married_names = array(); |
|
75 | + foreach (self::surnamesToAdd($xref, $gedrec) as $surname) { |
|
76 | + switch ($this->surname) { |
|
77 | + case 'add': |
|
78 | + $married_names[] = "\n2 _MARNM " . str_replace('/', '', $wife_name) . ' /' . $surname . '/'; |
|
79 | + break; |
|
80 | + case 'replace': |
|
81 | + if ($SURNAME_TRADITION === 'polish') { |
|
82 | + $surname = preg_replace(array('/ski$/', '/cki$/', '/dzki$/'), array('ska', 'cka', 'dzka'), $surname); |
|
83 | + } |
|
84 | + $married_names[] = "\n2 _MARNM " . preg_replace('!/.*/!', '/' . $surname . '/', $wife_name); |
|
85 | + break; |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - return preg_replace('/(^1 NAME .*([\r\n]+[2-9].*)*)/m', '\\1' . implode('', $married_names), $gedrec, 1); |
|
90 | - } |
|
89 | + return preg_replace('/(^1 NAME .*([\r\n]+[2-9].*)*)/m', '\\1' . implode('', $married_names), $gedrec, 1); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Generate a list of married surnames that are not already present. |
|
94 | - * |
|
95 | - * @param string $xref |
|
96 | - * @param string $gedrec |
|
97 | - * |
|
98 | - * @return string[] |
|
99 | - */ |
|
100 | - private function surnamesToAdd($xref, $gedrec) { |
|
101 | - $wife_surnames = self::surnames($xref, $gedrec); |
|
102 | - $husb_surnames = array(); |
|
103 | - $missing_surnames = array(); |
|
104 | - preg_match_all('/^1 FAMS @(.+)@/m', $gedrec, $fmatch); |
|
105 | - foreach ($fmatch[1] as $famid) { |
|
106 | - $famrec = BatchUpdateModule::getLatestRecord($famid, 'FAM'); |
|
107 | - if (preg_match('/^1 MARR/m', $famrec) && preg_match('/^1 HUSB @(.+)@/m', $famrec, $hmatch)) { |
|
108 | - $husbrec = BatchUpdateModule::getLatestRecord($hmatch[1], 'INDI'); |
|
109 | - $husb_surnames = array_unique(array_merge($husb_surnames, self::surnames($hmatch[1], $husbrec))); |
|
110 | - } |
|
111 | - } |
|
112 | - foreach ($husb_surnames as $husb_surname) { |
|
113 | - if (!in_array($husb_surname, $wife_surnames)) { |
|
114 | - $missing_surnames[] = $husb_surname; |
|
115 | - } |
|
116 | - } |
|
92 | + /** |
|
93 | + * Generate a list of married surnames that are not already present. |
|
94 | + * |
|
95 | + * @param string $xref |
|
96 | + * @param string $gedrec |
|
97 | + * |
|
98 | + * @return string[] |
|
99 | + */ |
|
100 | + private function surnamesToAdd($xref, $gedrec) { |
|
101 | + $wife_surnames = self::surnames($xref, $gedrec); |
|
102 | + $husb_surnames = array(); |
|
103 | + $missing_surnames = array(); |
|
104 | + preg_match_all('/^1 FAMS @(.+)@/m', $gedrec, $fmatch); |
|
105 | + foreach ($fmatch[1] as $famid) { |
|
106 | + $famrec = BatchUpdateModule::getLatestRecord($famid, 'FAM'); |
|
107 | + if (preg_match('/^1 MARR/m', $famrec) && preg_match('/^1 HUSB @(.+)@/m', $famrec, $hmatch)) { |
|
108 | + $husbrec = BatchUpdateModule::getLatestRecord($hmatch[1], 'INDI'); |
|
109 | + $husb_surnames = array_unique(array_merge($husb_surnames, self::surnames($hmatch[1], $husbrec))); |
|
110 | + } |
|
111 | + } |
|
112 | + foreach ($husb_surnames as $husb_surname) { |
|
113 | + if (!in_array($husb_surname, $wife_surnames)) { |
|
114 | + $missing_surnames[] = $husb_surname; |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - return $missing_surnames; |
|
119 | - } |
|
118 | + return $missing_surnames; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Extract a list of surnames from a GEDCOM record. |
|
123 | - * |
|
124 | - * @param string $xref |
|
125 | - * @param string $gedrec |
|
126 | - * |
|
127 | - * @return string[] |
|
128 | - */ |
|
129 | - private function surnames($xref, $gedrec) { |
|
130 | - if (preg_match_all('/^(?:1 NAME|2 _MARNM) .*\/(.+)\//m', $gedrec, $match)) { |
|
131 | - return $match[1]; |
|
132 | - } else { |
|
133 | - return array(); |
|
134 | - } |
|
135 | - } |
|
121 | + /** |
|
122 | + * Extract a list of surnames from a GEDCOM record. |
|
123 | + * |
|
124 | + * @param string $xref |
|
125 | + * @param string $gedrec |
|
126 | + * |
|
127 | + * @return string[] |
|
128 | + */ |
|
129 | + private function surnames($xref, $gedrec) { |
|
130 | + if (preg_match_all('/^(?:1 NAME|2 _MARNM) .*\/(.+)\//m', $gedrec, $match)) { |
|
131 | + return $match[1]; |
|
132 | + } else { |
|
133 | + return array(); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Process the user-supplied options. |
|
139 | - */ |
|
140 | - public function getOptions() { |
|
141 | - parent::getOptions(); |
|
142 | - $this->surname = Filter::get('surname', 'add|replace', 'replace'); |
|
143 | - } |
|
137 | + /** |
|
138 | + * Process the user-supplied options. |
|
139 | + */ |
|
140 | + public function getOptions() { |
|
141 | + parent::getOptions(); |
|
142 | + $this->surname = Filter::get('surname', 'add|replace', 'replace'); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Generate a form to ask the user for options. |
|
147 | - * |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public function getOptionsForm() { |
|
151 | - return |
|
152 | - '<div class="form-group">' . |
|
153 | - '<label class="control-label col-sm-3">' . I18N::translate('Surname option') . '</label>' . |
|
154 | - '<div class="col-sm-9">' . |
|
155 | - '<select class="form-control" name="surname" onchange="reset_reload();">' . |
|
156 | - '<option value="replace" ' . |
|
157 | - ($this->surname == 'replace' ? 'selected' : '') . |
|
158 | - '">' . I18N::translate('Wife’s surname replaced by husband’s surname') . '</option><option value="add" ' . |
|
159 | - ($this->surname == 'add' ? 'selected' : '') . |
|
160 | - '">' . I18N::translate('Wife’s maiden surname becomes new given name') . '</option>' . |
|
161 | - '</select>' . |
|
162 | - '</div></div>' . |
|
163 | - parent::getOptionsForm(); |
|
164 | - } |
|
145 | + /** |
|
146 | + * Generate a form to ask the user for options. |
|
147 | + * |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public function getOptionsForm() { |
|
151 | + return |
|
152 | + '<div class="form-group">' . |
|
153 | + '<label class="control-label col-sm-3">' . I18N::translate('Surname option') . '</label>' . |
|
154 | + '<div class="col-sm-9">' . |
|
155 | + '<select class="form-control" name="surname" onchange="reset_reload();">' . |
|
156 | + '<option value="replace" ' . |
|
157 | + ($this->surname == 'replace' ? 'selected' : '') . |
|
158 | + '">' . I18N::translate('Wife’s surname replaced by husband’s surname') . '</option><option value="add" ' . |
|
159 | + ($this->surname == 'add' ? 'selected' : '') . |
|
160 | + '">' . I18N::translate('Wife’s maiden surname becomes new given name') . '</option>' . |
|
161 | + '</select>' . |
|
162 | + '</div></div>' . |
|
163 | + parent::getOptionsForm(); |
|
164 | + } |
|
165 | 165 | } |
@@ -74,15 +74,15 @@ |
||
74 | 74 | $married_names = array(); |
75 | 75 | foreach (self::surnamesToAdd($xref, $gedrec) as $surname) { |
76 | 76 | switch ($this->surname) { |
77 | - case 'add': |
|
78 | - $married_names[] = "\n2 _MARNM " . str_replace('/', '', $wife_name) . ' /' . $surname . '/'; |
|
79 | - break; |
|
80 | - case 'replace': |
|
81 | - if ($SURNAME_TRADITION === 'polish') { |
|
82 | - $surname = preg_replace(array('/ski$/', '/cki$/', '/dzki$/'), array('ska', 'cka', 'dzka'), $surname); |
|
83 | - } |
|
84 | - $married_names[] = "\n2 _MARNM " . preg_replace('!/.*/!', '/' . $surname . '/', $wife_name); |
|
85 | - break; |
|
77 | + case 'add': |
|
78 | + $married_names[] = "\n2 _MARNM " . str_replace('/', '', $wife_name) . ' /' . $surname . '/'; |
|
79 | + break; |
|
80 | + case 'replace': |
|
81 | + if ($SURNAME_TRADITION === 'polish') { |
|
82 | + $surname = preg_replace(array('/ski$/', '/cki$/', '/dzki$/'), array('ska', 'cka', 'dzka'), $surname); |
|
83 | + } |
|
84 | + $married_names[] = "\n2 _MARNM " . preg_replace('!/.*/!', '/' . $surname . '/', $wife_name); |
|
85 | + break; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 |
@@ -22,7 +22,8 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Class BatchUpdateMarriedNamesPlugin Batch Update plugin: add missing 2 _MARNM records |
24 | 24 | */ |
25 | -class BatchUpdateMarriedNamesPlugin extends BatchUpdateBasePlugin { |
|
25 | +class BatchUpdateMarriedNamesPlugin extends BatchUpdateBasePlugin |
|
26 | +{ |
|
26 | 27 | /** @var string User option: add or replace husband’s surname */ |
27 | 28 | private $surname; |
28 | 29 | |
@@ -31,7 +32,8 @@ discard block |
||
31 | 32 | * |
32 | 33 | * @return string |
33 | 34 | */ |
34 | - public function getName() { |
|
35 | + public function getName() |
|
36 | + { |
|
35 | 37 | return I18N::translate('Add missing married names'); |
36 | 38 | } |
37 | 39 | |
@@ -40,7 +42,8 @@ discard block |
||
40 | 42 | * |
41 | 43 | * @return string |
42 | 44 | */ |
43 | - public function getDescription() { |
|
45 | + public function getDescription() |
|
46 | + { |
|
44 | 47 | return I18N::translate('You can make it easier to search for married women by recording their married name. However not all women take their husband’s surname, so beware of introducing incorrect information into your database.'); |
45 | 48 | } |
46 | 49 | |
@@ -52,7 +55,8 @@ discard block |
||
52 | 55 | * |
53 | 56 | * @return bool |
54 | 57 | */ |
55 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
58 | + public function doesRecordNeedUpdate($xref, $gedrec) |
|
59 | + { |
|
56 | 60 | return preg_match('/^1 SEX F/m', $gedrec) && preg_match('/^1 NAME /m', $gedrec) && self::surnamesToAdd($xref, $gedrec); |
57 | 61 | } |
58 | 62 | |
@@ -64,7 +68,8 @@ discard block |
||
64 | 68 | * |
65 | 69 | * @return string |
66 | 70 | */ |
67 | - public function updateRecord($xref, $gedrec) { |
|
71 | + public function updateRecord($xref, $gedrec) |
|
72 | + { |
|
68 | 73 | global $WT_TREE; |
69 | 74 | |
70 | 75 | $SURNAME_TRADITION = $WT_TREE->getPreference('SURNAME_TRADITION'); |
@@ -97,7 +102,8 @@ discard block |
||
97 | 102 | * |
98 | 103 | * @return string[] |
99 | 104 | */ |
100 | - private function surnamesToAdd($xref, $gedrec) { |
|
105 | + private function surnamesToAdd($xref, $gedrec) |
|
106 | + { |
|
101 | 107 | $wife_surnames = self::surnames($xref, $gedrec); |
102 | 108 | $husb_surnames = array(); |
103 | 109 | $missing_surnames = array(); |
@@ -126,7 +132,8 @@ discard block |
||
126 | 132 | * |
127 | 133 | * @return string[] |
128 | 134 | */ |
129 | - private function surnames($xref, $gedrec) { |
|
135 | + private function surnames($xref, $gedrec) |
|
136 | + { |
|
130 | 137 | if (preg_match_all('/^(?:1 NAME|2 _MARNM) .*\/(.+)\//m', $gedrec, $match)) { |
131 | 138 | return $match[1]; |
132 | 139 | } else { |
@@ -137,7 +144,8 @@ discard block |
||
137 | 144 | /** |
138 | 145 | * Process the user-supplied options. |
139 | 146 | */ |
140 | - public function getOptions() { |
|
147 | + public function getOptions() |
|
148 | + { |
|
141 | 149 | parent::getOptions(); |
142 | 150 | $this->surname = Filter::get('surname', 'add|replace', 'replace'); |
143 | 151 | } |
@@ -147,7 +155,8 @@ discard block |
||
147 | 155 | * |
148 | 156 | * @return string |
149 | 157 | */ |
150 | - public function getOptionsForm() { |
|
158 | + public function getOptionsForm() |
|
159 | + { |
|
151 | 160 | return |
152 | 161 | '<div class="form-group">' . |
153 | 162 | '<label class="control-label col-sm-3">' . I18N::translate('Surname option') . '</label>' . |
@@ -21,57 +21,57 @@ |
||
21 | 21 | * Class BatchUpdateNameFormatPlugin Batch Update plugin: fix spacing in names, particularly that before/after the surname slashes |
22 | 22 | */ |
23 | 23 | class BatchUpdateNameFormatPlugin extends BatchUpdateBasePlugin { |
24 | - /** |
|
25 | - * User-friendly name for this plugin. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return I18N::translate('Fix name slashes and spaces'); |
|
31 | - } |
|
24 | + /** |
|
25 | + * User-friendly name for this plugin. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return I18N::translate('Fix name slashes and spaces'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Description / help-text for this plugin. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getDescription() { |
|
39 | - return I18N::translate('Correct NAME records of the form “John/DOE/” or “John /DOE”, as produced by older genealogy programs.'); |
|
40 | - } |
|
33 | + /** |
|
34 | + * Description / help-text for this plugin. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getDescription() { |
|
39 | + return I18N::translate('Correct NAME records of the form “John/DOE/” or “John /DOE”, as produced by older genealogy programs.'); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Does this record need updating? |
|
44 | - * |
|
45 | - * @param string $xref |
|
46 | - * @param string $gedrec |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
51 | - return |
|
52 | - preg_match('/^(?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*\/[^\/\n]*$/m', $gedrec) || |
|
53 | - preg_match('/^(?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*[^\/ ]\//m', $gedrec); |
|
54 | - } |
|
42 | + /** |
|
43 | + * Does this record need updating? |
|
44 | + * |
|
45 | + * @param string $xref |
|
46 | + * @param string $gedrec |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function doesRecordNeedUpdate($xref, $gedrec) { |
|
51 | + return |
|
52 | + preg_match('/^(?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*\/[^\/\n]*$/m', $gedrec) || |
|
53 | + preg_match('/^(?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*[^\/ ]\//m', $gedrec); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Apply any updates to this record |
|
58 | - * |
|
59 | - * @param string $xref |
|
60 | - * @param string $gedrec |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function updateRecord($xref, $gedrec) { |
|
65 | - return preg_replace( |
|
66 | - array( |
|
67 | - '/^((?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*\/[^\/\n]*)$/m', |
|
68 | - '/^((?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*[^\/ ])(\/)/m', |
|
69 | - ), |
|
70 | - array( |
|
71 | - '$1/', |
|
72 | - '$1 $2', |
|
73 | - ), |
|
74 | - $gedrec |
|
75 | - ); |
|
76 | - } |
|
56 | + /** |
|
57 | + * Apply any updates to this record |
|
58 | + * |
|
59 | + * @param string $xref |
|
60 | + * @param string $gedrec |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function updateRecord($xref, $gedrec) { |
|
65 | + return preg_replace( |
|
66 | + array( |
|
67 | + '/^((?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*\/[^\/\n]*)$/m', |
|
68 | + '/^((?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*[^\/ ])(\/)/m', |
|
69 | + ), |
|
70 | + array( |
|
71 | + '$1/', |
|
72 | + '$1 $2', |
|
73 | + ), |
|
74 | + $gedrec |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | } |
@@ -20,13 +20,15 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Class BatchUpdateNameFormatPlugin Batch Update plugin: fix spacing in names, particularly that before/after the surname slashes |
22 | 22 | */ |
23 | -class BatchUpdateNameFormatPlugin extends BatchUpdateBasePlugin { |
|
23 | +class BatchUpdateNameFormatPlugin extends BatchUpdateBasePlugin |
|
24 | +{ |
|
24 | 25 | /** |
25 | 26 | * User-friendly name for this plugin. |
26 | 27 | * |
27 | 28 | * @return string |
28 | 29 | */ |
29 | - public function getName() { |
|
30 | + public function getName() |
|
31 | + { |
|
30 | 32 | return I18N::translate('Fix name slashes and spaces'); |
31 | 33 | } |
32 | 34 | |
@@ -35,7 +37,8 @@ discard block |
||
35 | 37 | * |
36 | 38 | * @return string |
37 | 39 | */ |
38 | - public function getDescription() { |
|
40 | + public function getDescription() |
|
41 | + { |
|
39 | 42 | return I18N::translate('Correct NAME records of the form “John/DOE/” or “John /DOE”, as produced by older genealogy programs.'); |
40 | 43 | } |
41 | 44 | |
@@ -47,7 +50,8 @@ discard block |
||
47 | 50 | * |
48 | 51 | * @return bool |
49 | 52 | */ |
50 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
53 | + public function doesRecordNeedUpdate($xref, $gedrec) |
|
54 | + { |
|
51 | 55 | return |
52 | 56 | preg_match('/^(?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*\/[^\/\n]*$/m', $gedrec) || |
53 | 57 | preg_match('/^(?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*[^\/ ]\//m', $gedrec); |
@@ -61,7 +65,8 @@ discard block |
||
61 | 65 | * |
62 | 66 | * @return string |
63 | 67 | */ |
64 | - public function updateRecord($xref, $gedrec) { |
|
68 | + public function updateRecord($xref, $gedrec) |
|
69 | + { |
|
65 | 70 | return preg_replace( |
66 | 71 | array( |
67 | 72 | '/^((?:1 NAME|2 (?:FONE|ROMN|_MARNM|_AKA|_HEB)) [^\/\n]*\/[^\/\n]*)$/m', |
@@ -23,155 +23,155 @@ |
||
23 | 23 | * Class BatchUpdateSearchReplacePlugin Batch Update plugin: search/replace |
24 | 24 | */ |
25 | 25 | class BatchUpdateSearchReplacePlugin extends BatchUpdateBasePlugin { |
26 | - /** @var string Search string */ |
|
27 | - private $search; |
|
28 | - |
|
29 | - /** @var string Replace string */ |
|
30 | - private $replace; |
|
31 | - |
|
32 | - /** @var string simple/wildcards/regex */ |
|
33 | - private $method; |
|
34 | - |
|
35 | - /** @var string Search string, converted to a regex */ |
|
36 | - private $regex; |
|
37 | - |
|
38 | - /** @var string "i" for case insensitive, "" for case sensitive */ |
|
39 | - private $case; |
|
40 | - |
|
41 | - /** @var string Message for bad user parameters */ |
|
42 | - private $error; |
|
43 | - |
|
44 | - /** |
|
45 | - * User-friendly name for this plugin. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getName() { |
|
50 | - return I18N::translate('Search and replace'); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Description / help-text for this plugin. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getDescription() { |
|
59 | - return /* I18N: Description of the “Search and replace” option of the batch update module */ I18N::translate('Search and replace text, using simple searches or advanced pattern matching.'); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * This plugin will update all types of record. |
|
64 | - * |
|
65 | - * @return string[] |
|
66 | - */ |
|
67 | - public function getRecordTypesToUpdate() { |
|
68 | - return array('INDI', 'FAM', 'SOUR', 'REPO', 'NOTE', 'OBJE'); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Does this record need updating? |
|
73 | - * |
|
74 | - * @param string $xref |
|
75 | - * @param string $gedrec |
|
76 | - * |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
80 | - return !$this->error && preg_match('/(?:' . $this->regex . ')/mu' . $this->case, $gedrec); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Apply any updates to this record |
|
85 | - * |
|
86 | - * @param string $xref |
|
87 | - * @param string $gedrec |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function updateRecord($xref, $gedrec) { |
|
92 | - // Allow "\n" to indicate a line-feed in replacement text. |
|
93 | - // Back-references such as $1, $2 are handled automatically. |
|
94 | - return preg_replace('/' . $this->regex . '/mu' . $this->case, str_replace('\n', "\n", $this->replace), $gedrec); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Process the user-supplied options. |
|
99 | - */ |
|
100 | - public function getOptions() { |
|
101 | - parent::getOptions(); |
|
102 | - $this->search = Filter::get('search'); |
|
103 | - $this->replace = Filter::get('replace'); |
|
104 | - $this->method = Filter::get('method', 'exact|words|wildcards|regex', 'exact'); |
|
105 | - $this->case = Filter::get('case', 'i'); |
|
106 | - |
|
107 | - $this->error = ''; |
|
108 | - switch ($this->method) { |
|
109 | - case 'exact': |
|
110 | - $this->regex = preg_quote($this->search, '/'); |
|
111 | - break; |
|
112 | - case 'words': |
|
113 | - $this->regex = '\b' . preg_quote($this->search, '/') . '\b'; |
|
114 | - break; |
|
115 | - case 'wildcards': |
|
116 | - $this->regex = '\b' . str_replace(array('\*', '\?'), array('.*', '.'), preg_quote($this->search, '/')) . '\b'; |
|
117 | - break; |
|
118 | - case 'regex': |
|
119 | - $this->regex = $this->search; |
|
120 | - // Check for invalid regular expressions. |
|
121 | - // A valid regex on a null string returns zero. |
|
122 | - // An invalid regex on a null string returns false and throws a warning. |
|
123 | - try { |
|
124 | - preg_match('/' . $this->search . '/', null); |
|
125 | - } catch (\ErrorException $ex) { |
|
126 | - $this->error = '<div class="alert alert-danger">' . /* I18N: http://en.wikipedia.org/wiki/Regular_expression */ I18N::translate('The regular expression appears to contain an error. It can’t be used.') . '</div>'; |
|
127 | - } |
|
128 | - break; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Generate a form to ask the user for options. |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function getOptionsForm() { |
|
138 | - $descriptions = array( |
|
139 | - 'exact' => I18N::translate('Match the exact text, even if it occurs in the middle of a word.'), |
|
140 | - 'words' => I18N::translate('Match the exact text, unless it occurs in the middle of a word.'), |
|
141 | - 'wildcards' => I18N::translate('Use a “?” to match a single character, use “*” to match zero or more characters.'), |
|
142 | - 'regex' => /* I18N: http://en.wikipedia.org/wiki/Regular_expression */ I18N::translate('Regular expressions are an advanced pattern matching technique.') . '<br>' . /* I18N: %s is a URL */ I18N::translate('See %s for more information.', '<a href="http://php.net/manual/regexp.reference.php">php.net/manual/regexp.reference.php</a>'), |
|
143 | - ); |
|
144 | - |
|
145 | - return |
|
146 | - '<div class="form-group">' . |
|
147 | - '<label class="control-label col-sm-3">' . I18N::translate('Search text/pattern') . '</label>' . |
|
148 | - '<div class="col-sm-9">' . |
|
149 | - '<input class="form-control" name="search" size="40" value="' . Filter::escapeHtml($this->search) . |
|
150 | - '" onchange="this.form.submit();">' . |
|
151 | - '</div></div>' . |
|
152 | - '<div class="form-group">' . |
|
153 | - '<label class="control-label col-sm-3">' . I18N::translate('Replacement text') . '</label>' . |
|
154 | - '<div class="col-sm-9">' . |
|
155 | - '<input class="form-control" name="replace" size="40" value="' . Filter::escapeHtml($this->replace) . |
|
156 | - '" onchange="this.form.submit();"></td></tr>' . |
|
157 | - '</div></div>' . |
|
158 | - '<div class="form-group">' . |
|
159 | - '<label class="control-label col-sm-3">' . I18N::translate('Search method') . '</label>' . |
|
160 | - '<div class="col-sm-9">' . |
|
161 | - '<select class="form-control" name="method" onchange="this.form.submit();">' . |
|
162 | - '<option value="exact" ' . ($this->method == 'exact' ? 'selected' : '') . '>' . I18N::translate('Exact text') . '</option>' . |
|
163 | - '<option value="words" ' . ($this->method == 'words' ? 'selected' : '') . '>' . I18N::translate('Whole words only') . '</option>' . |
|
164 | - '<option value="wildcards" ' . ($this->method == 'wildcards' ? 'selected' : '') . '>' . I18N::translate('Wildcards') . '</option>' . |
|
165 | - '<option value="regex" ' . ($this->method == 'regex' ? 'selected' : '') . '>' . I18N::translate('Regular expression') . '</option>' . |
|
166 | - '</select>' . |
|
167 | - '<p class="small text-muted">' . $descriptions[$this->method] . '</p>' . $this->error . |
|
168 | - '</div></div>' . |
|
169 | - '<div class="form-group">' . |
|
170 | - '<label class="control-label col-sm-3">' . I18N::translate('Case insensitive') . '</label>' . |
|
171 | - '<div class="col-sm-9">' . |
|
172 | - FunctionsEdit::radioButtons('case', array('I' => I18N::translate('no'), 'i' => I18N::translate('yes')), ($this->case ? 'i' : 'I'), 'class="radio-inline" onchange="this.form.submit();"') . |
|
173 | - '<p class="small text-muted">' . /* I18N: Help text for "Case insensitive" searches */ I18N::translate('Match both upper and lower case letters.') . '</p>' . |
|
174 | - '</div></div>' . |
|
175 | - parent::getOptionsForm(); |
|
176 | - } |
|
26 | + /** @var string Search string */ |
|
27 | + private $search; |
|
28 | + |
|
29 | + /** @var string Replace string */ |
|
30 | + private $replace; |
|
31 | + |
|
32 | + /** @var string simple/wildcards/regex */ |
|
33 | + private $method; |
|
34 | + |
|
35 | + /** @var string Search string, converted to a regex */ |
|
36 | + private $regex; |
|
37 | + |
|
38 | + /** @var string "i" for case insensitive, "" for case sensitive */ |
|
39 | + private $case; |
|
40 | + |
|
41 | + /** @var string Message for bad user parameters */ |
|
42 | + private $error; |
|
43 | + |
|
44 | + /** |
|
45 | + * User-friendly name for this plugin. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getName() { |
|
50 | + return I18N::translate('Search and replace'); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Description / help-text for this plugin. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getDescription() { |
|
59 | + return /* I18N: Description of the “Search and replace” option of the batch update module */ I18N::translate('Search and replace text, using simple searches or advanced pattern matching.'); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * This plugin will update all types of record. |
|
64 | + * |
|
65 | + * @return string[] |
|
66 | + */ |
|
67 | + public function getRecordTypesToUpdate() { |
|
68 | + return array('INDI', 'FAM', 'SOUR', 'REPO', 'NOTE', 'OBJE'); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Does this record need updating? |
|
73 | + * |
|
74 | + * @param string $xref |
|
75 | + * @param string $gedrec |
|
76 | + * |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function doesRecordNeedUpdate($xref, $gedrec) { |
|
80 | + return !$this->error && preg_match('/(?:' . $this->regex . ')/mu' . $this->case, $gedrec); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Apply any updates to this record |
|
85 | + * |
|
86 | + * @param string $xref |
|
87 | + * @param string $gedrec |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function updateRecord($xref, $gedrec) { |
|
92 | + // Allow "\n" to indicate a line-feed in replacement text. |
|
93 | + // Back-references such as $1, $2 are handled automatically. |
|
94 | + return preg_replace('/' . $this->regex . '/mu' . $this->case, str_replace('\n', "\n", $this->replace), $gedrec); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Process the user-supplied options. |
|
99 | + */ |
|
100 | + public function getOptions() { |
|
101 | + parent::getOptions(); |
|
102 | + $this->search = Filter::get('search'); |
|
103 | + $this->replace = Filter::get('replace'); |
|
104 | + $this->method = Filter::get('method', 'exact|words|wildcards|regex', 'exact'); |
|
105 | + $this->case = Filter::get('case', 'i'); |
|
106 | + |
|
107 | + $this->error = ''; |
|
108 | + switch ($this->method) { |
|
109 | + case 'exact': |
|
110 | + $this->regex = preg_quote($this->search, '/'); |
|
111 | + break; |
|
112 | + case 'words': |
|
113 | + $this->regex = '\b' . preg_quote($this->search, '/') . '\b'; |
|
114 | + break; |
|
115 | + case 'wildcards': |
|
116 | + $this->regex = '\b' . str_replace(array('\*', '\?'), array('.*', '.'), preg_quote($this->search, '/')) . '\b'; |
|
117 | + break; |
|
118 | + case 'regex': |
|
119 | + $this->regex = $this->search; |
|
120 | + // Check for invalid regular expressions. |
|
121 | + // A valid regex on a null string returns zero. |
|
122 | + // An invalid regex on a null string returns false and throws a warning. |
|
123 | + try { |
|
124 | + preg_match('/' . $this->search . '/', null); |
|
125 | + } catch (\ErrorException $ex) { |
|
126 | + $this->error = '<div class="alert alert-danger">' . /* I18N: http://en.wikipedia.org/wiki/Regular_expression */ I18N::translate('The regular expression appears to contain an error. It can’t be used.') . '</div>'; |
|
127 | + } |
|
128 | + break; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Generate a form to ask the user for options. |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function getOptionsForm() { |
|
138 | + $descriptions = array( |
|
139 | + 'exact' => I18N::translate('Match the exact text, even if it occurs in the middle of a word.'), |
|
140 | + 'words' => I18N::translate('Match the exact text, unless it occurs in the middle of a word.'), |
|
141 | + 'wildcards' => I18N::translate('Use a “?” to match a single character, use “*” to match zero or more characters.'), |
|
142 | + 'regex' => /* I18N: http://en.wikipedia.org/wiki/Regular_expression */ I18N::translate('Regular expressions are an advanced pattern matching technique.') . '<br>' . /* I18N: %s is a URL */ I18N::translate('See %s for more information.', '<a href="http://php.net/manual/regexp.reference.php">php.net/manual/regexp.reference.php</a>'), |
|
143 | + ); |
|
144 | + |
|
145 | + return |
|
146 | + '<div class="form-group">' . |
|
147 | + '<label class="control-label col-sm-3">' . I18N::translate('Search text/pattern') . '</label>' . |
|
148 | + '<div class="col-sm-9">' . |
|
149 | + '<input class="form-control" name="search" size="40" value="' . Filter::escapeHtml($this->search) . |
|
150 | + '" onchange="this.form.submit();">' . |
|
151 | + '</div></div>' . |
|
152 | + '<div class="form-group">' . |
|
153 | + '<label class="control-label col-sm-3">' . I18N::translate('Replacement text') . '</label>' . |
|
154 | + '<div class="col-sm-9">' . |
|
155 | + '<input class="form-control" name="replace" size="40" value="' . Filter::escapeHtml($this->replace) . |
|
156 | + '" onchange="this.form.submit();"></td></tr>' . |
|
157 | + '</div></div>' . |
|
158 | + '<div class="form-group">' . |
|
159 | + '<label class="control-label col-sm-3">' . I18N::translate('Search method') . '</label>' . |
|
160 | + '<div class="col-sm-9">' . |
|
161 | + '<select class="form-control" name="method" onchange="this.form.submit();">' . |
|
162 | + '<option value="exact" ' . ($this->method == 'exact' ? 'selected' : '') . '>' . I18N::translate('Exact text') . '</option>' . |
|
163 | + '<option value="words" ' . ($this->method == 'words' ? 'selected' : '') . '>' . I18N::translate('Whole words only') . '</option>' . |
|
164 | + '<option value="wildcards" ' . ($this->method == 'wildcards' ? 'selected' : '') . '>' . I18N::translate('Wildcards') . '</option>' . |
|
165 | + '<option value="regex" ' . ($this->method == 'regex' ? 'selected' : '') . '>' . I18N::translate('Regular expression') . '</option>' . |
|
166 | + '</select>' . |
|
167 | + '<p class="small text-muted">' . $descriptions[$this->method] . '</p>' . $this->error . |
|
168 | + '</div></div>' . |
|
169 | + '<div class="form-group">' . |
|
170 | + '<label class="control-label col-sm-3">' . I18N::translate('Case insensitive') . '</label>' . |
|
171 | + '<div class="col-sm-9">' . |
|
172 | + FunctionsEdit::radioButtons('case', array('I' => I18N::translate('no'), 'i' => I18N::translate('yes')), ($this->case ? 'i' : 'I'), 'class="radio-inline" onchange="this.form.submit();"') . |
|
173 | + '<p class="small text-muted">' . /* I18N: Help text for "Case insensitive" searches */ I18N::translate('Match both upper and lower case letters.') . '</p>' . |
|
174 | + '</div></div>' . |
|
175 | + parent::getOptionsForm(); |
|
176 | + } |
|
177 | 177 | } |
@@ -106,26 +106,26 @@ |
||
106 | 106 | |
107 | 107 | $this->error = ''; |
108 | 108 | switch ($this->method) { |
109 | - case 'exact': |
|
110 | - $this->regex = preg_quote($this->search, '/'); |
|
111 | - break; |
|
112 | - case 'words': |
|
113 | - $this->regex = '\b' . preg_quote($this->search, '/') . '\b'; |
|
114 | - break; |
|
115 | - case 'wildcards': |
|
116 | - $this->regex = '\b' . str_replace(array('\*', '\?'), array('.*', '.'), preg_quote($this->search, '/')) . '\b'; |
|
117 | - break; |
|
118 | - case 'regex': |
|
119 | - $this->regex = $this->search; |
|
120 | - // Check for invalid regular expressions. |
|
121 | - // A valid regex on a null string returns zero. |
|
122 | - // An invalid regex on a null string returns false and throws a warning. |
|
123 | - try { |
|
124 | - preg_match('/' . $this->search . '/', null); |
|
125 | - } catch (\ErrorException $ex) { |
|
126 | - $this->error = '<div class="alert alert-danger">' . /* I18N: http://en.wikipedia.org/wiki/Regular_expression */ I18N::translate('The regular expression appears to contain an error. It can’t be used.') . '</div>'; |
|
127 | - } |
|
128 | - break; |
|
109 | + case 'exact': |
|
110 | + $this->regex = preg_quote($this->search, '/'); |
|
111 | + break; |
|
112 | + case 'words': |
|
113 | + $this->regex = '\b' . preg_quote($this->search, '/') . '\b'; |
|
114 | + break; |
|
115 | + case 'wildcards': |
|
116 | + $this->regex = '\b' . str_replace(array('\*', '\?'), array('.*', '.'), preg_quote($this->search, '/')) . '\b'; |
|
117 | + break; |
|
118 | + case 'regex': |
|
119 | + $this->regex = $this->search; |
|
120 | + // Check for invalid regular expressions. |
|
121 | + // A valid regex on a null string returns zero. |
|
122 | + // An invalid regex on a null string returns false and throws a warning. |
|
123 | + try { |
|
124 | + preg_match('/' . $this->search . '/', null); |
|
125 | + } catch (\ErrorException $ex) { |
|
126 | + $this->error = '<div class="alert alert-danger">' . /* I18N: http://en.wikipedia.org/wiki/Regular_expression */ I18N::translate('The regular expression appears to contain an error. It can’t be used.') . '</div>'; |
|
127 | + } |
|
128 | + break; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 |
@@ -22,7 +22,8 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Class BatchUpdateSearchReplacePlugin Batch Update plugin: search/replace |
24 | 24 | */ |
25 | -class BatchUpdateSearchReplacePlugin extends BatchUpdateBasePlugin { |
|
25 | +class BatchUpdateSearchReplacePlugin extends BatchUpdateBasePlugin |
|
26 | +{ |
|
26 | 27 | /** @var string Search string */ |
27 | 28 | private $search; |
28 | 29 | |
@@ -46,7 +47,8 @@ discard block |
||
46 | 47 | * |
47 | 48 | * @return string |
48 | 49 | */ |
49 | - public function getName() { |
|
50 | + public function getName() |
|
51 | + { |
|
50 | 52 | return I18N::translate('Search and replace'); |
51 | 53 | } |
52 | 54 | |
@@ -55,7 +57,8 @@ discard block |
||
55 | 57 | * |
56 | 58 | * @return string |
57 | 59 | */ |
58 | - public function getDescription() { |
|
60 | + public function getDescription() |
|
61 | + { |
|
59 | 62 | return /* I18N: Description of the “Search and replace” option of the batch update module */ I18N::translate('Search and replace text, using simple searches or advanced pattern matching.'); |
60 | 63 | } |
61 | 64 | |
@@ -64,7 +67,8 @@ discard block |
||
64 | 67 | * |
65 | 68 | * @return string[] |
66 | 69 | */ |
67 | - public function getRecordTypesToUpdate() { |
|
70 | + public function getRecordTypesToUpdate() |
|
71 | + { |
|
68 | 72 | return array('INDI', 'FAM', 'SOUR', 'REPO', 'NOTE', 'OBJE'); |
69 | 73 | } |
70 | 74 | |
@@ -76,7 +80,8 @@ discard block |
||
76 | 80 | * |
77 | 81 | * @return bool |
78 | 82 | */ |
79 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
83 | + public function doesRecordNeedUpdate($xref, $gedrec) |
|
84 | + { |
|
80 | 85 | return !$this->error && preg_match('/(?:' . $this->regex . ')/mu' . $this->case, $gedrec); |
81 | 86 | } |
82 | 87 | |
@@ -88,7 +93,8 @@ discard block |
||
88 | 93 | * |
89 | 94 | * @return string |
90 | 95 | */ |
91 | - public function updateRecord($xref, $gedrec) { |
|
96 | + public function updateRecord($xref, $gedrec) |
|
97 | + { |
|
92 | 98 | // Allow "\n" to indicate a line-feed in replacement text. |
93 | 99 | // Back-references such as $1, $2 are handled automatically. |
94 | 100 | return preg_replace('/' . $this->regex . '/mu' . $this->case, str_replace('\n', "\n", $this->replace), $gedrec); |
@@ -97,7 +103,8 @@ discard block |
||
97 | 103 | /** |
98 | 104 | * Process the user-supplied options. |
99 | 105 | */ |
100 | - public function getOptions() { |
|
106 | + public function getOptions() |
|
107 | + { |
|
101 | 108 | parent::getOptions(); |
102 | 109 | $this->search = Filter::get('search'); |
103 | 110 | $this->replace = Filter::get('replace'); |
@@ -134,7 +141,8 @@ discard block |
||
134 | 141 | * |
135 | 142 | * @return string |
136 | 143 | */ |
137 | - public function getOptionsForm() { |
|
144 | + public function getOptionsForm() |
|
145 | + { |
|
138 | 146 | $descriptions = array( |
139 | 147 | 'exact' => I18N::translate('Match the exact text, even if it occurs in the middle of a word.'), |
140 | 148 | 'words' => I18N::translate('Match the exact text, unless it occurs in the middle of a word.'), |
@@ -21,65 +21,65 @@ |
||
21 | 21 | * Class BatchUpdateDuplicateLinksPlugin Batch Update plugin: remove duplicate links in records |
22 | 22 | */ |
23 | 23 | class BatchUpdateDuplicateLinksPlugin extends BatchUpdateBasePlugin { |
24 | - /** |
|
25 | - * User-friendly name for this plugin. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return I18N::translate('Remove duplicate links'); |
|
31 | - } |
|
24 | + /** |
|
25 | + * User-friendly name for this plugin. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return I18N::translate('Remove duplicate links'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Description / help-text for this plugin. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getDescription() { |
|
39 | - return I18N::translate('A common error is to have multiple links to the same record, for example listing the same child more than once in a family record.'); |
|
40 | - } |
|
33 | + /** |
|
34 | + * Description / help-text for this plugin. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getDescription() { |
|
39 | + return I18N::translate('A common error is to have multiple links to the same record, for example listing the same child more than once in a family record.'); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * This plugin will update all types of record. |
|
44 | - * |
|
45 | - * @return string[] |
|
46 | - */ |
|
47 | - public function getRecordTypesToUpdate() { |
|
48 | - return array('INDI', 'FAM', 'SOUR', 'REPO', 'NOTE', 'OBJE'); |
|
49 | - } |
|
42 | + /** |
|
43 | + * This plugin will update all types of record. |
|
44 | + * |
|
45 | + * @return string[] |
|
46 | + */ |
|
47 | + public function getRecordTypesToUpdate() { |
|
48 | + return array('INDI', 'FAM', 'SOUR', 'REPO', 'NOTE', 'OBJE'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Does this record need updating? |
|
53 | - * |
|
54 | - * @param string $xref |
|
55 | - * @param string $gedrec |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
60 | - return |
|
61 | - preg_match('/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))(?:\n1.*(?:\n[2-9].*)*)*\1/', $gedrec) || |
|
62 | - preg_match('/(\n2.*@.+@.*(?:(?:\n[3-9].*)*))(?:\n2.*(?:\n[3-9].*)*)*\1/', $gedrec) || |
|
63 | - preg_match('/(\n3.*@.+@.*(?:(?:\n[4-9].*)*))(?:\n3.*(?:\n[4-9].*)*)*\1/', $gedrec); |
|
64 | - } |
|
51 | + /** |
|
52 | + * Does this record need updating? |
|
53 | + * |
|
54 | + * @param string $xref |
|
55 | + * @param string $gedrec |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function doesRecordNeedUpdate($xref, $gedrec) { |
|
60 | + return |
|
61 | + preg_match('/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))(?:\n1.*(?:\n[2-9].*)*)*\1/', $gedrec) || |
|
62 | + preg_match('/(\n2.*@.+@.*(?:(?:\n[3-9].*)*))(?:\n2.*(?:\n[3-9].*)*)*\1/', $gedrec) || |
|
63 | + preg_match('/(\n3.*@.+@.*(?:(?:\n[4-9].*)*))(?:\n3.*(?:\n[4-9].*)*)*\1/', $gedrec); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Apply any updates to this record |
|
68 | - * |
|
69 | - * @param string $xref |
|
70 | - * @param string $gedrec |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function updateRecord($xref, $gedrec) { |
|
75 | - return preg_replace( |
|
76 | - array( |
|
77 | - '/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))((?:\n1.*(?:\n[2-9].*)*)*\1)/', |
|
78 | - '/(\n2.*@.+@.*(?:(?:\n[3-9].*)*))((?:\n2.*(?:\n[3-9].*)*)*\1)/', |
|
79 | - '/(\n3.*@.+@.*(?:(?:\n[4-9].*)*))((?:\n3.*(?:\n[4-9].*)*)*\1)/', |
|
80 | - ), |
|
81 | - '$2', |
|
82 | - $gedrec |
|
83 | - ); |
|
84 | - } |
|
66 | + /** |
|
67 | + * Apply any updates to this record |
|
68 | + * |
|
69 | + * @param string $xref |
|
70 | + * @param string $gedrec |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function updateRecord($xref, $gedrec) { |
|
75 | + return preg_replace( |
|
76 | + array( |
|
77 | + '/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))((?:\n1.*(?:\n[2-9].*)*)*\1)/', |
|
78 | + '/(\n2.*@.+@.*(?:(?:\n[3-9].*)*))((?:\n2.*(?:\n[3-9].*)*)*\1)/', |
|
79 | + '/(\n3.*@.+@.*(?:(?:\n[4-9].*)*))((?:\n3.*(?:\n[4-9].*)*)*\1)/', |
|
80 | + ), |
|
81 | + '$2', |
|
82 | + $gedrec |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | } |
@@ -20,13 +20,15 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Class BatchUpdateDuplicateLinksPlugin Batch Update plugin: remove duplicate links in records |
22 | 22 | */ |
23 | -class BatchUpdateDuplicateLinksPlugin extends BatchUpdateBasePlugin { |
|
23 | +class BatchUpdateDuplicateLinksPlugin extends BatchUpdateBasePlugin |
|
24 | +{ |
|
24 | 25 | /** |
25 | 26 | * User-friendly name for this plugin. |
26 | 27 | * |
27 | 28 | * @return string |
28 | 29 | */ |
29 | - public function getName() { |
|
30 | + public function getName() |
|
31 | + { |
|
30 | 32 | return I18N::translate('Remove duplicate links'); |
31 | 33 | } |
32 | 34 | |
@@ -35,7 +37,8 @@ discard block |
||
35 | 37 | * |
36 | 38 | * @return string |
37 | 39 | */ |
38 | - public function getDescription() { |
|
40 | + public function getDescription() |
|
41 | + { |
|
39 | 42 | return I18N::translate('A common error is to have multiple links to the same record, for example listing the same child more than once in a family record.'); |
40 | 43 | } |
41 | 44 | |
@@ -44,7 +47,8 @@ discard block |
||
44 | 47 | * |
45 | 48 | * @return string[] |
46 | 49 | */ |
47 | - public function getRecordTypesToUpdate() { |
|
50 | + public function getRecordTypesToUpdate() |
|
51 | + { |
|
48 | 52 | return array('INDI', 'FAM', 'SOUR', 'REPO', 'NOTE', 'OBJE'); |
49 | 53 | } |
50 | 54 | |
@@ -56,7 +60,8 @@ discard block |
||
56 | 60 | * |
57 | 61 | * @return bool |
58 | 62 | */ |
59 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
63 | + public function doesRecordNeedUpdate($xref, $gedrec) |
|
64 | + { |
|
60 | 65 | return |
61 | 66 | preg_match('/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))(?:\n1.*(?:\n[2-9].*)*)*\1/', $gedrec) || |
62 | 67 | preg_match('/(\n2.*@.+@.*(?:(?:\n[3-9].*)*))(?:\n2.*(?:\n[3-9].*)*)*\1/', $gedrec) || |
@@ -71,7 +76,8 @@ discard block |
||
71 | 76 | * |
72 | 77 | * @return string |
73 | 78 | */ |
74 | - public function updateRecord($xref, $gedrec) { |
|
79 | + public function updateRecord($xref, $gedrec) |
|
80 | + { |
|
75 | 81 | return preg_replace( |
76 | 82 | array( |
77 | 83 | '/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))((?:\n1.*(?:\n[2-9].*)*)*\1)/', |
@@ -32,123 +32,123 @@ |
||
32 | 32 | * string updateRecord($xref, $gedrec) |
33 | 33 | */ |
34 | 34 | class BatchUpdateBasePlugin { |
35 | - /** @var bool User option; update change record */ |
|
36 | - public $chan = false; |
|
35 | + /** @var bool User option; update change record */ |
|
36 | + public $chan = false; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Default is to operate on INDI records |
|
40 | - * |
|
41 | - * @return string[] |
|
42 | - */ |
|
43 | - public function getRecordTypesToUpdate() { |
|
44 | - return array('INDI'); |
|
45 | - } |
|
38 | + /** |
|
39 | + * Default is to operate on INDI records |
|
40 | + * |
|
41 | + * @return string[] |
|
42 | + */ |
|
43 | + public function getRecordTypesToUpdate() { |
|
44 | + return array('INDI'); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Default option is just the "don't update CHAN record" |
|
49 | - */ |
|
50 | - public function getOptions() { |
|
51 | - $this->chan = Filter::getBool('chan'); |
|
52 | - } |
|
47 | + /** |
|
48 | + * Default option is just the "don't update CHAN record" |
|
49 | + */ |
|
50 | + public function getOptions() { |
|
51 | + $this->chan = Filter::getBool('chan'); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Default option is just the "don't update CHAN record" |
|
56 | - * |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function getOptionsForm() { |
|
60 | - return |
|
61 | - '<div class="form-group">' . |
|
62 | - '<label class="control-label col-sm-3">' . I18N::translate('Keep the existing “last change” information') . '</label>' . |
|
63 | - '<div class="col-sm-9">' . |
|
64 | - FunctionsEdit::radioButtons('chan', array(0 => I18N::translate('no'), 1 => I18N::translate('yes')), ($this->chan ? 1 : 0), 'class="radio-inline" onchange="this.form.submit();"') . |
|
65 | - '</div></div>'; |
|
66 | - } |
|
54 | + /** |
|
55 | + * Default option is just the "don't update CHAN record" |
|
56 | + * |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function getOptionsForm() { |
|
60 | + return |
|
61 | + '<div class="form-group">' . |
|
62 | + '<label class="control-label col-sm-3">' . I18N::translate('Keep the existing “last change” information') . '</label>' . |
|
63 | + '<div class="col-sm-9">' . |
|
64 | + FunctionsEdit::radioButtons('chan', array(0 => I18N::translate('no'), 1 => I18N::translate('yes')), ($this->chan ? 1 : 0), 'class="radio-inline" onchange="this.form.submit();"') . |
|
65 | + '</div></div>'; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Default buttons are update and update_all |
|
70 | - * |
|
71 | - * @param string $xref |
|
72 | - * |
|
73 | - * @return string[] |
|
74 | - */ |
|
75 | - public function getActionButtons($xref) { |
|
76 | - if (Auth::user()->getPreference('auto_accept')) { |
|
77 | - return array( |
|
78 | - BatchUpdateModule::createSubmitButton(I18N::translate('Update'), $xref, 'update'), |
|
79 | - BatchUpdateModule::createSubmitButton(I18N::translate('Update all'), $xref, 'update_all'), |
|
80 | - ); |
|
81 | - } else { |
|
82 | - return array( |
|
83 | - BatchUpdateModule::createSubmitButton(I18N::translate('Update'), $xref, 'update'), |
|
84 | - ); |
|
85 | - } |
|
86 | - } |
|
68 | + /** |
|
69 | + * Default buttons are update and update_all |
|
70 | + * |
|
71 | + * @param string $xref |
|
72 | + * |
|
73 | + * @return string[] |
|
74 | + */ |
|
75 | + public function getActionButtons($xref) { |
|
76 | + if (Auth::user()->getPreference('auto_accept')) { |
|
77 | + return array( |
|
78 | + BatchUpdateModule::createSubmitButton(I18N::translate('Update'), $xref, 'update'), |
|
79 | + BatchUpdateModule::createSubmitButton(I18N::translate('Update all'), $xref, 'update_all'), |
|
80 | + ); |
|
81 | + } else { |
|
82 | + return array( |
|
83 | + BatchUpdateModule::createSubmitButton(I18N::translate('Update'), $xref, 'update'), |
|
84 | + ); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Default previewer for plugins with no custom preview. |
|
90 | - * |
|
91 | - * @param GedcomRecord $record |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getActionPreview(GedcomRecord $record) { |
|
96 | - $old_lines = preg_split('/[\n]+/', $record->getGedcom()); |
|
97 | - $new_lines = preg_split('/[\n]+/', $this->updateRecord($record->getXref(), $record->getGedcom())); |
|
98 | - $algorithm = new MyersDiff; |
|
99 | - $differences = $algorithm->calculate($old_lines, $new_lines); |
|
100 | - $diff_lines = array(); |
|
88 | + /** |
|
89 | + * Default previewer for plugins with no custom preview. |
|
90 | + * |
|
91 | + * @param GedcomRecord $record |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getActionPreview(GedcomRecord $record) { |
|
96 | + $old_lines = preg_split('/[\n]+/', $record->getGedcom()); |
|
97 | + $new_lines = preg_split('/[\n]+/', $this->updateRecord($record->getXref(), $record->getGedcom())); |
|
98 | + $algorithm = new MyersDiff; |
|
99 | + $differences = $algorithm->calculate($old_lines, $new_lines); |
|
100 | + $diff_lines = array(); |
|
101 | 101 | |
102 | - foreach ($differences as $difference) { |
|
103 | - switch ($difference[1]) { |
|
104 | - case MyersDiff::DELETE: |
|
105 | - $diff_lines[] = self::decorateDeletedText($difference[0]); |
|
106 | - break; |
|
107 | - case MyersDiff::INSERT: |
|
108 | - $diff_lines[] = self::decorateInsertedText($difference[0]); |
|
109 | - break; |
|
110 | - default: |
|
111 | - $diff_lines[] = $difference[0]; |
|
112 | - } |
|
113 | - } |
|
102 | + foreach ($differences as $difference) { |
|
103 | + switch ($difference[1]) { |
|
104 | + case MyersDiff::DELETE: |
|
105 | + $diff_lines[] = self::decorateDeletedText($difference[0]); |
|
106 | + break; |
|
107 | + case MyersDiff::INSERT: |
|
108 | + $diff_lines[] = self::decorateInsertedText($difference[0]); |
|
109 | + break; |
|
110 | + default: |
|
111 | + $diff_lines[] = $difference[0]; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - return '<pre class="gedcom-data">' . self::createEditLinks(implode("\n", $diff_lines)) . '</pre>'; |
|
116 | - } |
|
115 | + return '<pre class="gedcom-data">' . self::createEditLinks(implode("\n", $diff_lines)) . '</pre>'; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Decorate inserted text |
|
120 | - * |
|
121 | - * @param string $text |
|
122 | - * |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public static function decorateInsertedText($text) { |
|
126 | - return '<ins>' . $text . '</ins>'; |
|
127 | - } |
|
118 | + /** |
|
119 | + * Decorate inserted text |
|
120 | + * |
|
121 | + * @param string $text |
|
122 | + * |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public static function decorateInsertedText($text) { |
|
126 | + return '<ins>' . $text . '</ins>'; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Decorate deleted text |
|
131 | - * |
|
132 | - * @param string $text |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public static function decorateDeletedText($text) { |
|
137 | - return '<del>' . $text . '</del>'; |
|
138 | - } |
|
129 | + /** |
|
130 | + * Decorate deleted text |
|
131 | + * |
|
132 | + * @param string $text |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public static function decorateDeletedText($text) { |
|
137 | + return '<del>' . $text . '</del>'; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Converted gedcom links into editable links |
|
142 | - * |
|
143 | - * @param string $gedrec |
|
144 | - * |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - public static function createEditLinks($gedrec) { |
|
148 | - return preg_replace( |
|
149 | - "/@([^#@\n]+)@/m", |
|
150 | - '<a href="#" onclick="return edit_raw(\'\\1\');">@\\1@</a>', |
|
151 | - $gedrec |
|
152 | - ); |
|
153 | - } |
|
140 | + /** |
|
141 | + * Converted gedcom links into editable links |
|
142 | + * |
|
143 | + * @param string $gedrec |
|
144 | + * |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + public static function createEditLinks($gedrec) { |
|
148 | + return preg_replace( |
|
149 | + "/@([^#@\n]+)@/m", |
|
150 | + '<a href="#" onclick="return edit_raw(\'\\1\');">@\\1@</a>', |
|
151 | + $gedrec |
|
152 | + ); |
|
153 | + } |
|
154 | 154 | } |
@@ -101,14 +101,14 @@ |
||
101 | 101 | |
102 | 102 | foreach ($differences as $difference) { |
103 | 103 | switch ($difference[1]) { |
104 | - case MyersDiff::DELETE: |
|
105 | - $diff_lines[] = self::decorateDeletedText($difference[0]); |
|
106 | - break; |
|
107 | - case MyersDiff::INSERT: |
|
108 | - $diff_lines[] = self::decorateInsertedText($difference[0]); |
|
109 | - break; |
|
110 | - default: |
|
111 | - $diff_lines[] = $difference[0]; |
|
104 | + case MyersDiff::DELETE: |
|
105 | + $diff_lines[] = self::decorateDeletedText($difference[0]); |
|
106 | + break; |
|
107 | + case MyersDiff::INSERT: |
|
108 | + $diff_lines[] = self::decorateInsertedText($difference[0]); |
|
109 | + break; |
|
110 | + default: |
|
111 | + $diff_lines[] = $difference[0]; |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 |
@@ -31,7 +31,8 @@ discard block |
||
31 | 31 | * bool doesRecordNeedUpdate($xref, $gedrec) |
32 | 32 | * string updateRecord($xref, $gedrec) |
33 | 33 | */ |
34 | -class BatchUpdateBasePlugin { |
|
34 | +class BatchUpdateBasePlugin |
|
35 | +{ |
|
35 | 36 | /** @var bool User option; update change record */ |
36 | 37 | public $chan = false; |
37 | 38 | |
@@ -40,14 +41,16 @@ discard block |
||
40 | 41 | * |
41 | 42 | * @return string[] |
42 | 43 | */ |
43 | - public function getRecordTypesToUpdate() { |
|
44 | + public function getRecordTypesToUpdate() |
|
45 | + { |
|
44 | 46 | return array('INDI'); |
45 | 47 | } |
46 | 48 | |
47 | 49 | /** |
48 | 50 | * Default option is just the "don't update CHAN record" |
49 | 51 | */ |
50 | - public function getOptions() { |
|
52 | + public function getOptions() |
|
53 | + { |
|
51 | 54 | $this->chan = Filter::getBool('chan'); |
52 | 55 | } |
53 | 56 | |
@@ -56,7 +59,8 @@ discard block |
||
56 | 59 | * |
57 | 60 | * @return string |
58 | 61 | */ |
59 | - public function getOptionsForm() { |
|
62 | + public function getOptionsForm() |
|
63 | + { |
|
60 | 64 | return |
61 | 65 | '<div class="form-group">' . |
62 | 66 | '<label class="control-label col-sm-3">' . I18N::translate('Keep the existing “last change” information') . '</label>' . |
@@ -72,7 +76,8 @@ discard block |
||
72 | 76 | * |
73 | 77 | * @return string[] |
74 | 78 | */ |
75 | - public function getActionButtons($xref) { |
|
79 | + public function getActionButtons($xref) |
|
80 | + { |
|
76 | 81 | if (Auth::user()->getPreference('auto_accept')) { |
77 | 82 | return array( |
78 | 83 | BatchUpdateModule::createSubmitButton(I18N::translate('Update'), $xref, 'update'), |
@@ -92,7 +97,8 @@ discard block |
||
92 | 97 | * |
93 | 98 | * @return string |
94 | 99 | */ |
95 | - public function getActionPreview(GedcomRecord $record) { |
|
100 | + public function getActionPreview(GedcomRecord $record) |
|
101 | + { |
|
96 | 102 | $old_lines = preg_split('/[\n]+/', $record->getGedcom()); |
97 | 103 | $new_lines = preg_split('/[\n]+/', $this->updateRecord($record->getXref(), $record->getGedcom())); |
98 | 104 | $algorithm = new MyersDiff; |
@@ -122,7 +128,8 @@ discard block |
||
122 | 128 | * |
123 | 129 | * @return string |
124 | 130 | */ |
125 | - public static function decorateInsertedText($text) { |
|
131 | + public static function decorateInsertedText($text) |
|
132 | + { |
|
126 | 133 | return '<ins>' . $text . '</ins>'; |
127 | 134 | } |
128 | 135 | |
@@ -133,7 +140,8 @@ discard block |
||
133 | 140 | * |
134 | 141 | * @return string |
135 | 142 | */ |
136 | - public static function decorateDeletedText($text) { |
|
143 | + public static function decorateDeletedText($text) |
|
144 | + { |
|
137 | 145 | return '<del>' . $text . '</del>'; |
138 | 146 | } |
139 | 147 | |
@@ -144,7 +152,8 @@ discard block |
||
144 | 152 | * |
145 | 153 | * @return string |
146 | 154 | */ |
147 | - public static function createEditLinks($gedrec) { |
|
155 | + public static function createEditLinks($gedrec) |
|
156 | + { |
|
148 | 157 | return preg_replace( |
149 | 158 | "/@([^#@\n]+)@/m", |
150 | 159 | '<a href="#" onclick="return edit_raw(\'\\1\');">@\\1@</a>', |
@@ -22,47 +22,47 @@ |
||
22 | 22 | * Class BatchUpdateMissingDeathPlugin Batch Update plugin: add missing 1 BIRT/DEAT Y |
23 | 23 | */ |
24 | 24 | class BatchUpdateMissingDeathPlugin extends BatchUpdateBasePlugin { |
25 | - /** |
|
26 | - * User-friendly name for this plugin. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function getName() { |
|
31 | - return I18N::translate('Add missing death records'); |
|
32 | - } |
|
25 | + /** |
|
26 | + * User-friendly name for this plugin. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function getName() { |
|
31 | + return I18N::translate('Add missing death records'); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Description / help-text for this plugin. |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function getDescription() { |
|
40 | - return I18N::translate('You can speed up the privacy calculations by adding a death record to individuals whose death can be inferred from other dates, but who do not have a record of death, burial, cremation, etc.'); |
|
41 | - } |
|
34 | + /** |
|
35 | + * Description / help-text for this plugin. |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function getDescription() { |
|
40 | + return I18N::translate('You can speed up the privacy calculations by adding a death record to individuals whose death can be inferred from other dates, but who do not have a record of death, burial, cremation, etc.'); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Does this record need updating? |
|
45 | - * |
|
46 | - * @param string $xref |
|
47 | - * @param string $gedrec |
|
48 | - * |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
52 | - global $WT_TREE; |
|
43 | + /** |
|
44 | + * Does this record need updating? |
|
45 | + * |
|
46 | + * @param string $xref |
|
47 | + * @param string $gedrec |
|
48 | + * |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function doesRecordNeedUpdate($xref, $gedrec) { |
|
52 | + global $WT_TREE; |
|
53 | 53 | |
54 | - return !preg_match('/\n1 (' . WT_EVENTS_DEAT . ')/', $gedrec) && Individual::getInstance($xref, $WT_TREE)->isDead(); |
|
55 | - } |
|
54 | + return !preg_match('/\n1 (' . WT_EVENTS_DEAT . ')/', $gedrec) && Individual::getInstance($xref, $WT_TREE)->isDead(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Apply any updates to this record |
|
59 | - * |
|
60 | - * @param string $xref |
|
61 | - * @param string $gedrec |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function updateRecord($xref, $gedrec) { |
|
66 | - return $gedrec . "\n1 DEAT Y"; |
|
67 | - } |
|
57 | + /** |
|
58 | + * Apply any updates to this record |
|
59 | + * |
|
60 | + * @param string $xref |
|
61 | + * @param string $gedrec |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function updateRecord($xref, $gedrec) { |
|
66 | + return $gedrec . "\n1 DEAT Y"; |
|
67 | + } |
|
68 | 68 | } |
@@ -21,13 +21,15 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Class BatchUpdateMissingDeathPlugin Batch Update plugin: add missing 1 BIRT/DEAT Y |
23 | 23 | */ |
24 | -class BatchUpdateMissingDeathPlugin extends BatchUpdateBasePlugin { |
|
24 | +class BatchUpdateMissingDeathPlugin extends BatchUpdateBasePlugin |
|
25 | +{ |
|
25 | 26 | /** |
26 | 27 | * User-friendly name for this plugin. |
27 | 28 | * |
28 | 29 | * @return string |
29 | 30 | */ |
30 | - public function getName() { |
|
31 | + public function getName() |
|
32 | + { |
|
31 | 33 | return I18N::translate('Add missing death records'); |
32 | 34 | } |
33 | 35 | |
@@ -36,7 +38,8 @@ discard block |
||
36 | 38 | * |
37 | 39 | * @return string |
38 | 40 | */ |
39 | - public function getDescription() { |
|
41 | + public function getDescription() |
|
42 | + { |
|
40 | 43 | return I18N::translate('You can speed up the privacy calculations by adding a death record to individuals whose death can be inferred from other dates, but who do not have a record of death, burial, cremation, etc.'); |
41 | 44 | } |
42 | 45 | |
@@ -48,7 +51,8 @@ discard block |
||
48 | 51 | * |
49 | 52 | * @return bool |
50 | 53 | */ |
51 | - public function doesRecordNeedUpdate($xref, $gedrec) { |
|
54 | + public function doesRecordNeedUpdate($xref, $gedrec) |
|
55 | + { |
|
52 | 56 | global $WT_TREE; |
53 | 57 | |
54 | 58 | return !preg_match('/\n1 (' . WT_EVENTS_DEAT . ')/', $gedrec) && Individual::getInstance($xref, $WT_TREE)->isDead(); |
@@ -62,7 +66,8 @@ discard block |
||
62 | 66 | * |
63 | 67 | * @return string |
64 | 68 | */ |
65 | - public function updateRecord($xref, $gedrec) { |
|
69 | + public function updateRecord($xref, $gedrec) |
|
70 | + { |
|
66 | 71 | return $gedrec . "\n1 DEAT Y"; |
67 | 72 | } |
68 | 73 | } |
@@ -24,55 +24,55 @@ |
||
24 | 24 | * Class HourglassChartModule |
25 | 25 | */ |
26 | 26 | class HourglassChartModule extends AbstractModule implements ModuleChartInterface { |
27 | - /** |
|
28 | - * How should this module be labelled on tabs, menus, etc.? |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function getTitle() { |
|
33 | - return /* I18N: Name of a module/chart */ I18N::translate('Hourglass chart'); |
|
34 | - } |
|
27 | + /** |
|
28 | + * How should this module be labelled on tabs, menus, etc.? |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function getTitle() { |
|
33 | + return /* I18N: Name of a module/chart */ I18N::translate('Hourglass chart'); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * A sentence describing what this module does. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function getDescription() { |
|
42 | - return /* I18N: Description of the “HourglassChart” module */ I18N::translate('An hourglass chart of an individual’s ancestors and descendants.'); |
|
43 | - } |
|
36 | + /** |
|
37 | + * A sentence describing what this module does. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function getDescription() { |
|
42 | + return /* I18N: Description of the “HourglassChart” module */ I18N::translate('An hourglass chart of an individual’s ancestors and descendants.'); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * What is the default access level for this module? |
|
47 | - * |
|
48 | - * Some modules are aimed at admins or managers, and are not generally shown to users. |
|
49 | - * |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function defaultAccessLevel() { |
|
53 | - return Auth::PRIV_PRIVATE; |
|
54 | - } |
|
45 | + /** |
|
46 | + * What is the default access level for this module? |
|
47 | + * |
|
48 | + * Some modules are aimed at admins or managers, and are not generally shown to users. |
|
49 | + * |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function defaultAccessLevel() { |
|
53 | + return Auth::PRIV_PRIVATE; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Return a menu item for this chart. |
|
58 | - * |
|
59 | - * @return Menu|null |
|
60 | - */ |
|
61 | - public function getChartMenu(Individual $individual) { |
|
62 | - return new Menu( |
|
63 | - $this->getTitle(), |
|
64 | - 'hourglass.php?rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), |
|
65 | - 'menu-chart-hourglass', |
|
66 | - array('rel' => 'nofollow') |
|
67 | - ); |
|
68 | - } |
|
56 | + /** |
|
57 | + * Return a menu item for this chart. |
|
58 | + * |
|
59 | + * @return Menu|null |
|
60 | + */ |
|
61 | + public function getChartMenu(Individual $individual) { |
|
62 | + return new Menu( |
|
63 | + $this->getTitle(), |
|
64 | + 'hourglass.php?rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), |
|
65 | + 'menu-chart-hourglass', |
|
66 | + array('rel' => 'nofollow') |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Return a menu item for this chart - for use in individual boxes. |
|
72 | - * |
|
73 | - * @return Menu|null |
|
74 | - */ |
|
75 | - public function getBoxChartMenu(Individual $individual) { |
|
76 | - return $this->getChartMenu($individual); |
|
77 | - } |
|
70 | + /** |
|
71 | + * Return a menu item for this chart - for use in individual boxes. |
|
72 | + * |
|
73 | + * @return Menu|null |
|
74 | + */ |
|
75 | + public function getBoxChartMenu(Individual $individual) { |
|
76 | + return $this->getChartMenu($individual); |
|
77 | + } |
|
78 | 78 | } |
@@ -23,13 +23,15 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * Class HourglassChartModule |
25 | 25 | */ |
26 | -class HourglassChartModule extends AbstractModule implements ModuleChartInterface { |
|
26 | +class HourglassChartModule extends AbstractModule implements ModuleChartInterface |
|
27 | +{ |
|
27 | 28 | /** |
28 | 29 | * How should this module be labelled on tabs, menus, etc.? |
29 | 30 | * |
30 | 31 | * @return string |
31 | 32 | */ |
32 | - public function getTitle() { |
|
33 | + public function getTitle() |
|
34 | + { |
|
33 | 35 | return /* I18N: Name of a module/chart */ I18N::translate('Hourglass chart'); |
34 | 36 | } |
35 | 37 | |
@@ -38,7 +40,8 @@ discard block |
||
38 | 40 | * |
39 | 41 | * @return string |
40 | 42 | */ |
41 | - public function getDescription() { |
|
43 | + public function getDescription() |
|
44 | + { |
|
42 | 45 | return /* I18N: Description of the “HourglassChart” module */ I18N::translate('An hourglass chart of an individual’s ancestors and descendants.'); |
43 | 46 | } |
44 | 47 | |
@@ -49,7 +52,8 @@ discard block |
||
49 | 52 | * |
50 | 53 | * @return int |
51 | 54 | */ |
52 | - public function defaultAccessLevel() { |
|
55 | + public function defaultAccessLevel() |
|
56 | + { |
|
53 | 57 | return Auth::PRIV_PRIVATE; |
54 | 58 | } |
55 | 59 | |
@@ -58,7 +62,8 @@ discard block |
||
58 | 62 | * |
59 | 63 | * @return Menu|null |
60 | 64 | */ |
61 | - public function getChartMenu(Individual $individual) { |
|
65 | + public function getChartMenu(Individual $individual) |
|
66 | + { |
|
62 | 67 | return new Menu( |
63 | 68 | $this->getTitle(), |
64 | 69 | 'hourglass.php?rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), |
@@ -72,7 +77,8 @@ discard block |
||
72 | 77 | * |
73 | 78 | * @return Menu|null |
74 | 79 | */ |
75 | - public function getBoxChartMenu(Individual $individual) { |
|
80 | + public function getBoxChartMenu(Individual $individual) |
|
81 | + { |
|
76 | 82 | return $this->getChartMenu($individual); |
77 | 83 | } |
78 | 84 | } |