@@ -24,89 +24,89 @@ discard block |
||
24 | 24 | * {@inhericDoc} |
25 | 25 | * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent() |
26 | 26 | */ |
27 | - protected function renderContent() { |
|
27 | + protected function renderContent() { |
|
28 | 28 | |
29 | - $max_details_gen = $this->data->get('max_details_gen'); |
|
30 | - $analysis_level = $this->data->get('analysis_level'); |
|
31 | - $results_by_gen = $this->data->get('results_by_generations'); |
|
32 | - $display_all_places = $this->data->get('display_all_places', true); |
|
29 | + $max_details_gen = $this->data->get('max_details_gen'); |
|
30 | + $analysis_level = $this->data->get('analysis_level'); |
|
31 | + $results_by_gen = $this->data->get('results_by_generations'); |
|
32 | + $display_all_places = $this->data->get('display_all_places', true); |
|
33 | 33 | |
34 | - $html = |
|
35 | - '<div id="geodispersion_gen"> |
|
34 | + $html = |
|
35 | + '<div id="geodispersion_gen"> |
|
36 | 36 | <table id="geodispersion_gentable" class="center">'; |
37 | 37 | |
38 | - foreach($results_by_gen as $gen => $genData){ |
|
39 | - $html .= |
|
40 | - '<tr> |
|
38 | + foreach($results_by_gen as $gen => $genData){ |
|
39 | + $html .= |
|
40 | + '<tr> |
|
41 | 41 | <td class="descriptionbox">' . |
42 | - I18N::translate("Generation %s", I18N::number($gen)). |
|
43 | - ($display_all_places ? '<br />' : ' '). |
|
44 | - I18N::translate('(%s)', I18N::percentage(Functions::safeDivision($genData['sum'] + $genData['other'], $genData['sum'] + $genData['other'] + $genData['unknown']),1)) . |
|
45 | - '</td> |
|
42 | + I18N::translate("Generation %s", I18N::number($gen)). |
|
43 | + ($display_all_places ? '<br />' : ' '). |
|
44 | + I18N::translate('(%s)', I18N::percentage(Functions::safeDivision($genData['sum'] + $genData['other'], $genData['sum'] + $genData['other'] + $genData['unknown']),1)) . |
|
45 | + '</td> |
|
46 | 46 | <td class="optionbox left">'. |
47 | - ($display_all_places ? |
|
48 | - $this->htmlGenerationAllPlacesRow($genData, $analysis_level) : |
|
49 | - $this->htmlGenerationTopPlacesRow($genData, $analysis_level) |
|
50 | - ) . |
|
51 | - '</ditdv> |
|
47 | + ($display_all_places ? |
|
48 | + $this->htmlGenerationAllPlacesRow($genData, $analysis_level) : |
|
49 | + $this->htmlGenerationTopPlacesRow($genData, $analysis_level) |
|
50 | + ) . |
|
51 | + '</ditdv> |
|
52 | 52 | </tr>'; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - $html.= |
|
56 | - '</table> |
|
55 | + $html.= |
|
56 | + '</table> |
|
57 | 57 | <div class="left"> |
58 | 58 | <strong>' . I18N::translate('Interpretation help:') . '</strong> |
59 | 59 | <br />'. |
60 | - I18N::translate('<strong>Generation X (yy %%)</strong>: The percentage indicates the number of found places compared to the total number of ancestors in this generation.') . |
|
61 | - '<br />'; |
|
62 | - if(!is_null($max_details_gen) && $max_details_gen == 0){ |
|
63 | - $html .= I18N::translate('<strong><em>Place</em> or <em>Flag</em> aa (bb %%)</strong>: The first number indicates the total number of ancestors born in this place, the percentage relates this count to the total number of found places. No percentage means it is less than 10%%.').'<br />'; |
|
64 | - $html .= I18N::translate('If any, the darker area indicates the number of unknown places within the generation or places outside the analysed area, and its percentage compared to the number of ancestors. No percentage means it is less than 10%%.'); |
|
65 | - } |
|
66 | - else{ |
|
67 | - $html .= I18N::translate('<strong><em>Place</em> [aa - bb %%]</strong>: The first number indicates the total number of ancestors born in this place, the percentage compares this count to the total number of found places.').'<br />'; |
|
68 | - $html .= I18N::translate('Only the %d more frequent places for each generation are displayed.', $max_details_gen); |
|
69 | - } |
|
70 | - $html.= |
|
71 | - '</div> |
|
60 | + I18N::translate('<strong>Generation X (yy %%)</strong>: The percentage indicates the number of found places compared to the total number of ancestors in this generation.') . |
|
61 | + '<br />'; |
|
62 | + if(!is_null($max_details_gen) && $max_details_gen == 0){ |
|
63 | + $html .= I18N::translate('<strong><em>Place</em> or <em>Flag</em> aa (bb %%)</strong>: The first number indicates the total number of ancestors born in this place, the percentage relates this count to the total number of found places. No percentage means it is less than 10%%.').'<br />'; |
|
64 | + $html .= I18N::translate('If any, the darker area indicates the number of unknown places within the generation or places outside the analysed area, and its percentage compared to the number of ancestors. No percentage means it is less than 10%%.'); |
|
65 | + } |
|
66 | + else{ |
|
67 | + $html .= I18N::translate('<strong><em>Place</em> [aa - bb %%]</strong>: The first number indicates the total number of ancestors born in this place, the percentage compares this count to the total number of found places.').'<br />'; |
|
68 | + $html .= I18N::translate('Only the %d more frequent places for each generation are displayed.', $max_details_gen); |
|
69 | + } |
|
70 | + $html.= |
|
71 | + '</div> |
|
72 | 72 | </div>'; |
73 | 73 | |
74 | - return $html; |
|
75 | - } |
|
74 | + return $html; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * Return the HTML code to display a row with all places found in a generation. |
|
80 | - * |
|
81 | - * @param array $data Data array |
|
82 | - * @param int $analysis_level Level of subdivision of analysis |
|
83 | - * @return string HTML code for all places row |
|
84 | - */ |
|
85 | - protected function htmlGenerationAllPlacesRow($data, $analysis_level) { |
|
86 | - $html = |
|
87 | - '<table class="geodispersion_bigrow"> |
|
78 | + /** |
|
79 | + * Return the HTML code to display a row with all places found in a generation. |
|
80 | + * |
|
81 | + * @param array $data Data array |
|
82 | + * @param int $analysis_level Level of subdivision of analysis |
|
83 | + * @return string HTML code for all places row |
|
84 | + */ |
|
85 | + protected function htmlGenerationAllPlacesRow($data, $analysis_level) { |
|
86 | + $html = |
|
87 | + '<table class="geodispersion_bigrow"> |
|
88 | 88 | <tr>'; |
89 | 89 | |
90 | - $sum_gen = $data['sum']; |
|
91 | - $unknownother = $data['unknown'] + $data['other']; |
|
92 | - foreach($data['places'] as $placename=> $dataplace){ |
|
93 | - $levels = array_map('trim',explode(',', $placename)); |
|
94 | - $content = ''; |
|
95 | - if(isset($dataplace['flag'])){ |
|
96 | - $content .= '<td class="geodispersion_flag">'. FunctionsPrint::htmlPlaceIcon($dataplace['place'], $dataplace['flag']) .'</td><td>'; |
|
97 | - } |
|
98 | - else{ |
|
99 | - $content .= '<td><span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span><br/>'; |
|
100 | - } |
|
101 | - $count = $dataplace['count']; |
|
102 | - $content .= I18N::number($count); |
|
103 | - $perc = Functions::safeDivision($count, $sum_gen + $unknownother); |
|
104 | - $perc2= Functions::safeDivision($count, $sum_gen); |
|
105 | - if($perc2>=0.1) |
|
106 | - $content.= '<br/><span class="small">('.I18N::percentage($perc2, 1).')</span>'; |
|
107 | - $content .= '</td>'; |
|
90 | + $sum_gen = $data['sum']; |
|
91 | + $unknownother = $data['unknown'] + $data['other']; |
|
92 | + foreach($data['places'] as $placename=> $dataplace){ |
|
93 | + $levels = array_map('trim',explode(',', $placename)); |
|
94 | + $content = ''; |
|
95 | + if(isset($dataplace['flag'])){ |
|
96 | + $content .= '<td class="geodispersion_flag">'. FunctionsPrint::htmlPlaceIcon($dataplace['place'], $dataplace['flag']) .'</td><td>'; |
|
97 | + } |
|
98 | + else{ |
|
99 | + $content .= '<td><span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span><br/>'; |
|
100 | + } |
|
101 | + $count = $dataplace['count']; |
|
102 | + $content .= I18N::number($count); |
|
103 | + $perc = Functions::safeDivision($count, $sum_gen + $unknownother); |
|
104 | + $perc2= Functions::safeDivision($count, $sum_gen); |
|
105 | + if($perc2>=0.1) |
|
106 | + $content.= '<br/><span class="small">('.I18N::percentage($perc2, 1).')</span>'; |
|
107 | + $content .= '</td>'; |
|
108 | 108 | |
109 | - $html .= ' |
|
109 | + $html .= ' |
|
110 | 110 | <td class="geodispersion_rowitem" width="'.max(round(100*$perc, 0),1).'%"> |
111 | 111 | <table> |
112 | 112 | <tr> |
@@ -118,46 +118,46 @@ discard block |
||
118 | 118 | </tr> |
119 | 119 | </table> |
120 | 120 | </td>'; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - if($unknownother>0){ |
|
124 | - $perc= Functions::safeDivision($unknownother, $sum_gen + $unknownother); |
|
125 | - $html .='<td class="geodispersion_unknownitem left" >'.I18N::number($unknownother); |
|
126 | - if($perc>=0.1) $html.= '<br/><span class="small">('.I18N::percentage($perc, 1).')</span>'; |
|
127 | - $html .='</td>'; |
|
128 | - } |
|
123 | + if($unknownother>0){ |
|
124 | + $perc= Functions::safeDivision($unknownother, $sum_gen + $unknownother); |
|
125 | + $html .='<td class="geodispersion_unknownitem left" >'.I18N::number($unknownother); |
|
126 | + if($perc>=0.1) $html.= '<br/><span class="small">('.I18N::percentage($perc, 1).')</span>'; |
|
127 | + $html .='</td>'; |
|
128 | + } |
|
129 | 129 | |
130 | - $html .= |
|
131 | - '</tr> |
|
130 | + $html .= |
|
131 | + '</tr> |
|
132 | 132 | </table>'; |
133 | - return $html; |
|
134 | - } |
|
133 | + return $html; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * Returns the HTML code fo display a row of the Top Places found for a generation. |
138 | 138 | * |
139 | 139 | * @param array $data Data array |
140 | - * @param int $analysis_level Level of subdivision of analysis |
|
140 | + * @param int $analysis_level Level of subdivision of analysis |
|
141 | 141 | * @return string HTML code for Top Places row |
142 | 142 | */ |
143 | - protected function htmlGenerationTopPlacesRow($data, $analysis_level) { |
|
144 | - $tmp_places = array(); |
|
145 | - $sum_gen = $data['sum']; |
|
146 | - $other = $data['other']; |
|
143 | + protected function htmlGenerationTopPlacesRow($data, $analysis_level) { |
|
144 | + $tmp_places = array(); |
|
145 | + $sum_gen = $data['sum']; |
|
146 | + $other = $data['other']; |
|
147 | 147 | |
148 | - foreach($data['places'] as $placename => $count) { |
|
149 | - if($placename != 'other'){ |
|
150 | - $levels = array_map('trim',explode(',', $placename)); |
|
151 | - $placename = '<span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span>'; |
|
152 | - } |
|
153 | - else{ |
|
154 | - $placename = I18N::translate('Other places'); |
|
155 | - } |
|
156 | - $tmp_places[] = I18N::translate('<strong>%s</strong> [%d - %s]', $placename, $count, I18N::percentage(Functions::safeDivision($count, $sum_gen + $other), 1)); |
|
157 | - } |
|
148 | + foreach($data['places'] as $placename => $count) { |
|
149 | + if($placename != 'other'){ |
|
150 | + $levels = array_map('trim',explode(',', $placename)); |
|
151 | + $placename = '<span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span>'; |
|
152 | + } |
|
153 | + else{ |
|
154 | + $placename = I18N::translate('Other places'); |
|
155 | + } |
|
156 | + $tmp_places[] = I18N::translate('<strong>%s</strong> [%d - %s]', $placename, $count, I18N::percentage(Functions::safeDivision($count, $sum_gen + $other), 1)); |
|
157 | + } |
|
158 | 158 | |
159 | - return implode(I18N::$list_separator, $tmp_places); |
|
160 | - } |
|
159 | + return implode(I18N::$list_separator, $tmp_places); |
|
160 | + } |
|
161 | 161 | |
162 | 162 | } |
163 | 163 | |
164 | 164 | \ No newline at end of file |
@@ -21,130 +21,130 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class GeoAnalysisProvider { |
23 | 23 | |
24 | - /** |
|
25 | - * Reference tree |
|
26 | - * @var Tree $tree |
|
27 | - */ |
|
28 | - protected $tree; |
|
24 | + /** |
|
25 | + * Reference tree |
|
26 | + * @var Tree $tree |
|
27 | + */ |
|
28 | + protected $tree; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Cached hierarchy of places in the Gedcom file. |
|
32 | - * |
|
33 | - * @var (array|null) $place_hierarchy |
|
34 | - */ |
|
35 | - protected $place_hierarchy; |
|
30 | + /** |
|
31 | + * Cached hierarchy of places in the Gedcom file. |
|
32 | + * |
|
33 | + * @var (array|null) $place_hierarchy |
|
34 | + */ |
|
35 | + protected $place_hierarchy; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for GeoAnalysis Provider. |
|
39 | - * A provider is defined in relation to a specific tree. |
|
40 | - * |
|
41 | - * @param Tree $tree |
|
42 | - */ |
|
43 | - public function __construct(Tree $tree) { |
|
44 | - $this->tree = $tree; |
|
45 | - $this->place_hierarchy = null; |
|
46 | - } |
|
37 | + /** |
|
38 | + * Constructor for GeoAnalysis Provider. |
|
39 | + * A provider is defined in relation to a specific tree. |
|
40 | + * |
|
41 | + * @param Tree $tree |
|
42 | + */ |
|
43 | + public function __construct(Tree $tree) { |
|
44 | + $this->tree = $tree; |
|
45 | + $this->place_hierarchy = null; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Creates and returns a GeoAnalysis object from a data row. |
|
50 | - * The row data is expected to be an array with the indexes: |
|
51 | - * - majgd_id: geodispersion analysis ID |
|
52 | - * - majgd_descr: geodispersion analysis description/title |
|
53 | - * - majgd_sublevel: Analysis level |
|
54 | - * - majgd_useflagsgen: Use flags in places display |
|
55 | - * - majgd_detailsgen: Number of top places |
|
56 | - * - majgd_map: file name of the map |
|
57 | - * - majgd_toplevel: parent level for the map |
|
58 | - * |
|
59 | - * @param array $row |
|
60 | - * @return GeoAnalysis |
|
61 | - */ |
|
62 | - protected function loadGeoAnalysisFromRow($row) { |
|
63 | - $options = new GeoDisplayOptions(); |
|
64 | - $options |
|
65 | - ->setUsingFlags($row['majgd_useflagsgen'] == 'yes') |
|
66 | - ->setMaxDetailsInGen($row['majgd_detailsgen']); |
|
48 | + /** |
|
49 | + * Creates and returns a GeoAnalysis object from a data row. |
|
50 | + * The row data is expected to be an array with the indexes: |
|
51 | + * - majgd_id: geodispersion analysis ID |
|
52 | + * - majgd_descr: geodispersion analysis description/title |
|
53 | + * - majgd_sublevel: Analysis level |
|
54 | + * - majgd_useflagsgen: Use flags in places display |
|
55 | + * - majgd_detailsgen: Number of top places |
|
56 | + * - majgd_map: file name of the map |
|
57 | + * - majgd_toplevel: parent level for the map |
|
58 | + * |
|
59 | + * @param array $row |
|
60 | + * @return GeoAnalysis |
|
61 | + */ |
|
62 | + protected function loadGeoAnalysisFromRow($row) { |
|
63 | + $options = new GeoDisplayOptions(); |
|
64 | + $options |
|
65 | + ->setUsingFlags($row['majgd_useflagsgen'] == 'yes') |
|
66 | + ->setMaxDetailsInGen($row['majgd_detailsgen']); |
|
67 | 67 | |
68 | - if($row['majgd_map']) { |
|
69 | - $options |
|
70 | - ->setMap(new OutlineMap($row['majgd_map'])) |
|
71 | - ->setMapLevel($row['majgd_toplevel']); |
|
72 | - } |
|
68 | + if($row['majgd_map']) { |
|
69 | + $options |
|
70 | + ->setMap(new OutlineMap($row['majgd_map'])) |
|
71 | + ->setMapLevel($row['majgd_toplevel']); |
|
72 | + } |
|
73 | 73 | |
74 | - $enabled = true; |
|
75 | - if(isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') { |
|
76 | - $enabled = false; |
|
77 | - } |
|
74 | + $enabled = true; |
|
75 | + if(isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') { |
|
76 | + $enabled = false; |
|
77 | + } |
|
78 | 78 | |
79 | - return new GeoAnalysis( |
|
80 | - $this->tree, |
|
81 | - $row['majgd_id'], |
|
82 | - $row['majgd_descr'], |
|
83 | - $row['majgd_sublevel'], |
|
84 | - $options, |
|
85 | - $enabled |
|
86 | - ); |
|
87 | - } |
|
79 | + return new GeoAnalysis( |
|
80 | + $this->tree, |
|
81 | + $row['majgd_id'], |
|
82 | + $row['majgd_descr'], |
|
83 | + $row['majgd_sublevel'], |
|
84 | + $options, |
|
85 | + $enabled |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Returns the number of geographical analysis (active and inactive). |
|
91 | - * |
|
92 | - * @return int |
|
93 | - */ |
|
94 | - public function getGeoAnalysisCount() { |
|
95 | - return Database::prepare( |
|
96 | - 'SELECT COUNT(majgd_id)' . |
|
97 | - ' FROM `##maj_geodispersion`' . |
|
98 | - ' WHERE majgd_file = :gedcom_id' |
|
99 | - )->execute(array( |
|
100 | - 'gedcom_id' => $this->tree->getTreeId() |
|
101 | - ))->fetchOne(); |
|
102 | - } |
|
89 | + /** |
|
90 | + * Returns the number of geographical analysis (active and inactive). |
|
91 | + * |
|
92 | + * @return int |
|
93 | + */ |
|
94 | + public function getGeoAnalysisCount() { |
|
95 | + return Database::prepare( |
|
96 | + 'SELECT COUNT(majgd_id)' . |
|
97 | + ' FROM `##maj_geodispersion`' . |
|
98 | + ' WHERE majgd_file = :gedcom_id' |
|
99 | + )->execute(array( |
|
100 | + 'gedcom_id' => $this->tree->getTreeId() |
|
101 | + ))->fetchOne(); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Get a geographical analysis by its ID. |
|
106 | - * The function can only search for only enabled analysis, or all. |
|
107 | - * |
|
108 | - * @param int $id geodispersion analysis ID |
|
109 | - * @param bool $only_enabled Search for only enabled geodispersion analysis |
|
110 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis|NULL |
|
111 | - */ |
|
112 | - public function getGeoAnalysis($id, $only_enabled = true) { |
|
113 | - $args = array ( |
|
114 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
115 | - 'ga_id' => $id |
|
116 | - ); |
|
104 | + /** |
|
105 | + * Get a geographical analysis by its ID. |
|
106 | + * The function can only search for only enabled analysis, or all. |
|
107 | + * |
|
108 | + * @param int $id geodispersion analysis ID |
|
109 | + * @param bool $only_enabled Search for only enabled geodispersion analysis |
|
110 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis|NULL |
|
111 | + */ |
|
112 | + public function getGeoAnalysis($id, $only_enabled = true) { |
|
113 | + $args = array ( |
|
114 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
115 | + 'ga_id' => $id |
|
116 | + ); |
|
117 | 117 | |
118 | - $sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' . |
|
119 | - ' FROM `##maj_geodispersion`' . |
|
120 | - ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'; |
|
121 | - if($only_enabled) { |
|
122 | - $sql .= ' AND majgd_status = :status'; |
|
123 | - $args['status'] = 'enabled'; |
|
124 | - } |
|
125 | - $sql .= ' ORDER BY majgd_descr'; |
|
118 | + $sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' . |
|
119 | + ' FROM `##maj_geodispersion`' . |
|
120 | + ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'; |
|
121 | + if($only_enabled) { |
|
122 | + $sql .= ' AND majgd_status = :status'; |
|
123 | + $args['status'] = 'enabled'; |
|
124 | + } |
|
125 | + $sql .= ' ORDER BY majgd_descr'; |
|
126 | 126 | |
127 | - $ga_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC); |
|
127 | + $ga_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC); |
|
128 | 128 | |
129 | - if($ga_array) { |
|
130 | - return $this->loadGeoAnalysisFromRow($ga_array); |
|
131 | - } |
|
129 | + if($ga_array) { |
|
130 | + return $this->loadGeoAnalysisFromRow($ga_array); |
|
131 | + } |
|
132 | 132 | |
133 | - return null; |
|
134 | - } |
|
133 | + return null; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Add a new geodispersion analysis in the database, in a transactional manner. |
|
138 | - * When successful, eturns the newly created GeoAnalysis object. |
|
139 | - * |
|
140 | - * @param string $description geodispersion analysis title |
|
141 | - * @param int $analysis_level Analysis level |
|
142 | - * @param string $map_file Filename of the map |
|
143 | - * @param int $map_top_level Parent level of the map |
|
144 | - * @param bool $use_flags Use flag in the place display |
|
145 | - * @param int $gen_details Number of top places to display |
|
146 | - * @return GeoAnalysis |
|
147 | - */ |
|
136 | + /** |
|
137 | + * Add a new geodispersion analysis in the database, in a transactional manner. |
|
138 | + * When successful, eturns the newly created GeoAnalysis object. |
|
139 | + * |
|
140 | + * @param string $description geodispersion analysis title |
|
141 | + * @param int $analysis_level Analysis level |
|
142 | + * @param string $map_file Filename of the map |
|
143 | + * @param int $map_top_level Parent level of the map |
|
144 | + * @param bool $use_flags Use flag in the place display |
|
145 | + * @param int $gen_details Number of top places to display |
|
146 | + * @return GeoAnalysis |
|
147 | + */ |
|
148 | 148 | public function createGeoAnalysis($description, $analysis_level, $map_file, $map_top_level, $use_flags, $gen_details) { |
149 | 149 | try{ |
150 | 150 | Database::beginTransaction(); |
@@ -174,17 +174,17 @@ discard block |
||
174 | 174 | Log::addErrorLog('A new Geo Analysis failed to be created. Transaction rollbacked. Parameters ['.$description.', '.$analysis_level.','.$map_file.','.$map_top_level.','.$use_flags.', '.$gen_details.']. Exception: '.$ex->getMessage()); |
175 | 175 | } |
176 | 176 | return $ga; |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Update a geodispersion analysis in the database, in transactional manner. |
|
181 | - * When successful, returns the updated GeoAnalysis object |
|
182 | - * |
|
183 | - * @param GeoAnalysis $ga |
|
184 | - * @return GeoAnalysis |
|
185 | - */ |
|
186 | - public function updateGeoAnalysis(GeoAnalysis $ga) { |
|
187 | - try { |
|
179 | + /** |
|
180 | + * Update a geodispersion analysis in the database, in transactional manner. |
|
181 | + * When successful, returns the updated GeoAnalysis object |
|
182 | + * |
|
183 | + * @param GeoAnalysis $ga |
|
184 | + * @return GeoAnalysis |
|
185 | + */ |
|
186 | + public function updateGeoAnalysis(GeoAnalysis $ga) { |
|
187 | + try { |
|
188 | 188 | Database::beginTransaction(); |
189 | 189 | |
190 | 190 | Database::prepare( |
@@ -217,236 +217,236 @@ discard block |
||
217 | 217 | $ga = null; |
218 | 218 | } |
219 | 219 | return $ga; |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * Set the status of a specific analysis. |
|
224 | - * The status can be enabled (true), or disabled (false). |
|
225 | - * |
|
226 | - * @param GeoAnalysis $ga |
|
227 | - * @param bool $status |
|
228 | - */ |
|
229 | - public function setGeoAnalysisStatus(GeoAnalysis $ga, $status) { |
|
230 | - Database::prepare( |
|
231 | - 'UPDATE `##maj_geodispersion`'. |
|
232 | - ' SET majgd_status = :status'. |
|
233 | - ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id' |
|
234 | - )->execute(array( |
|
235 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
236 | - 'status' => $status ? 'enabled' : 'disabled', |
|
237 | - 'ga_id' => $ga->getId() |
|
238 | - )); |
|
239 | - } |
|
222 | + /** |
|
223 | + * Set the status of a specific analysis. |
|
224 | + * The status can be enabled (true), or disabled (false). |
|
225 | + * |
|
226 | + * @param GeoAnalysis $ga |
|
227 | + * @param bool $status |
|
228 | + */ |
|
229 | + public function setGeoAnalysisStatus(GeoAnalysis $ga, $status) { |
|
230 | + Database::prepare( |
|
231 | + 'UPDATE `##maj_geodispersion`'. |
|
232 | + ' SET majgd_status = :status'. |
|
233 | + ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id' |
|
234 | + )->execute(array( |
|
235 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
236 | + 'status' => $status ? 'enabled' : 'disabled', |
|
237 | + 'ga_id' => $ga->getId() |
|
238 | + )); |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Delete a geodispersion analysis from the database. |
|
243 | - * |
|
244 | - * @param GeoAnalysis $ga |
|
245 | - */ |
|
246 | - public function deleteGeoAnalysis(GeoAnalysis $ga) { |
|
247 | - Database::prepare( |
|
248 | - 'DELETE FROM `##maj_geodispersion`'. |
|
249 | - ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id' |
|
250 | - )->execute(array( |
|
251 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
252 | - 'ga_id' => $ga->getId() |
|
253 | - )); |
|
254 | - } |
|
241 | + /** |
|
242 | + * Delete a geodispersion analysis from the database. |
|
243 | + * |
|
244 | + * @param GeoAnalysis $ga |
|
245 | + */ |
|
246 | + public function deleteGeoAnalysis(GeoAnalysis $ga) { |
|
247 | + Database::prepare( |
|
248 | + 'DELETE FROM `##maj_geodispersion`'. |
|
249 | + ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id' |
|
250 | + )->execute(array( |
|
251 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
252 | + 'ga_id' => $ga->getId() |
|
253 | + )); |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * Return the list of geodispersion analysis recorded and enabled for a specific GEDCOM |
|
258 | - * |
|
259 | - * @return array List of enabled maps |
|
260 | - */ |
|
261 | - public function getGeoAnalysisList(){ |
|
262 | - $res = array(); |
|
256 | + /** |
|
257 | + * Return the list of geodispersion analysis recorded and enabled for a specific GEDCOM |
|
258 | + * |
|
259 | + * @return array List of enabled maps |
|
260 | + */ |
|
261 | + public function getGeoAnalysisList(){ |
|
262 | + $res = array(); |
|
263 | 263 | |
264 | - $list = Database::prepare( |
|
265 | - 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen' . |
|
266 | - ' FROM `##maj_geodispersion`' . |
|
267 | - ' WHERE majgd_file = :gedcom_id AND majgd_status = :status'. |
|
268 | - ' ORDER BY majgd_descr' |
|
269 | - )->execute(array( |
|
270 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
271 | - 'status' => 'enabled' |
|
272 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
264 | + $list = Database::prepare( |
|
265 | + 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen' . |
|
266 | + ' FROM `##maj_geodispersion`' . |
|
267 | + ' WHERE majgd_file = :gedcom_id AND majgd_status = :status'. |
|
268 | + ' ORDER BY majgd_descr' |
|
269 | + )->execute(array( |
|
270 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
271 | + 'status' => 'enabled' |
|
272 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
273 | 273 | |
274 | - foreach($list as $ga) { |
|
275 | - $res[] = $this->loadGeoAnalysisFromRow($ga); |
|
276 | - } |
|
274 | + foreach($list as $ga) { |
|
275 | + $res[] = $this->loadGeoAnalysisFromRow($ga); |
|
276 | + } |
|
277 | 277 | |
278 | - return $res; |
|
279 | - } |
|
278 | + return $res; |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Return the list of geodispersion analysis matching specified criterias. |
|
283 | - * |
|
284 | - * @param string $search Search criteria in analysis description |
|
285 | - * @param array $order_by Columns to order by |
|
286 | - * @param int $start Offset to start with (for pagination) |
|
287 | - * @param int|null $limit Max number of items to return (for pagination) |
|
288 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
|
289 | - */ |
|
290 | - public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null){ |
|
291 | - $res = array(); |
|
281 | + /** |
|
282 | + * Return the list of geodispersion analysis matching specified criterias. |
|
283 | + * |
|
284 | + * @param string $search Search criteria in analysis description |
|
285 | + * @param array $order_by Columns to order by |
|
286 | + * @param int $start Offset to start with (for pagination) |
|
287 | + * @param int|null $limit Max number of items to return (for pagination) |
|
288 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
|
289 | + */ |
|
290 | + public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null){ |
|
291 | + $res = array(); |
|
292 | 292 | |
293 | - $sql = |
|
294 | - 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' . |
|
295 | - ' FROM `##maj_geodispersion`' . |
|
296 | - ' WHERE majgd_file = :gedcom_id'; |
|
293 | + $sql = |
|
294 | + 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' . |
|
295 | + ' FROM `##maj_geodispersion`' . |
|
296 | + ' WHERE majgd_file = :gedcom_id'; |
|
297 | 297 | |
298 | - $args = array('gedcom_id'=> $this->tree->getTreeId()); |
|
298 | + $args = array('gedcom_id'=> $this->tree->getTreeId()); |
|
299 | 299 | |
300 | - if($search) { |
|
301 | - $sql .= ' AND majgd_descr LIKE CONCAT(\'%\', :search, \'%\')'; |
|
302 | - $args['search'] = $search; |
|
303 | - } |
|
300 | + if($search) { |
|
301 | + $sql .= ' AND majgd_descr LIKE CONCAT(\'%\', :search, \'%\')'; |
|
302 | + $args['search'] = $search; |
|
303 | + } |
|
304 | 304 | |
305 | - if ($order_by) { |
|
306 | - $sql .= ' ORDER BY '; |
|
307 | - foreach ($order_by as $key => $value) { |
|
308 | - if ($key > 0) { |
|
309 | - $sql .= ','; |
|
310 | - } |
|
305 | + if ($order_by) { |
|
306 | + $sql .= ' ORDER BY '; |
|
307 | + foreach ($order_by as $key => $value) { |
|
308 | + if ($key > 0) { |
|
309 | + $sql .= ','; |
|
310 | + } |
|
311 | 311 | |
312 | - switch ($value['dir']) { |
|
313 | - case 'asc': |
|
314 | - $sql .= $value['column'] . ' ASC '; |
|
315 | - break; |
|
316 | - case 'desc': |
|
317 | - $sql .= $value['column'] . ' DESC '; |
|
318 | - break; |
|
319 | - } |
|
320 | - } |
|
321 | - } else { |
|
322 | - $sql = " ORDER BY majgd_descr ASC"; |
|
323 | - } |
|
312 | + switch ($value['dir']) { |
|
313 | + case 'asc': |
|
314 | + $sql .= $value['column'] . ' ASC '; |
|
315 | + break; |
|
316 | + case 'desc': |
|
317 | + $sql .= $value['column'] . ' DESC '; |
|
318 | + break; |
|
319 | + } |
|
320 | + } |
|
321 | + } else { |
|
322 | + $sql = " ORDER BY majgd_descr ASC"; |
|
323 | + } |
|
324 | 324 | |
325 | - if ($limit) { |
|
326 | - $sql .= " LIMIT :limit OFFSET :offset"; |
|
327 | - $args['limit'] = $limit; |
|
328 | - $args['offset'] = $start; |
|
329 | - } |
|
325 | + if ($limit) { |
|
326 | + $sql .= " LIMIT :limit OFFSET :offset"; |
|
327 | + $args['limit'] = $limit; |
|
328 | + $args['offset'] = $start; |
|
329 | + } |
|
330 | 330 | |
331 | - $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC); |
|
331 | + $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC); |
|
332 | 332 | |
333 | - foreach($data as $ga) { |
|
334 | - $res[] = $this->loadGeoAnalysisFromRow($ga); |
|
335 | - } |
|
333 | + foreach($data as $ga) { |
|
334 | + $res[] = $this->loadGeoAnalysisFromRow($ga); |
|
335 | + } |
|
336 | 336 | |
337 | - return $res; |
|
338 | - } |
|
337 | + return $res; |
|
338 | + } |
|
339 | 339 | |
340 | - /** |
|
341 | - * Returns the infered place hierarchy, determined from the Gedcom data. |
|
342 | - * Depending on the data, it can be based on the Gedcom Header description, or from a place example. |
|
343 | - * This is returned as an associative array: |
|
344 | - * - type: describe the source of the data (<em>header<em> / <em>data</em>) |
|
345 | - * - hierarchy: an array of the place hierarchy (in reverse order of the gedcom) |
|
346 | - * |
|
347 | - * @return array |
|
348 | - */ |
|
349 | - public function getPlacesHierarchy() { |
|
350 | - if(!$this->place_hierarchy) { |
|
351 | - if($place_structure = $this->getPlacesHierarchyFromHeader()) { |
|
352 | - $this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure); |
|
353 | - } |
|
354 | - else { |
|
355 | - $this->place_hierarchy = array('type' => 'data', 'hierarchy' => $this->getPlacesHierarchyFromData()); |
|
356 | - } |
|
357 | - } |
|
358 | - return $this->place_hierarchy; |
|
359 | - } |
|
340 | + /** |
|
341 | + * Returns the infered place hierarchy, determined from the Gedcom data. |
|
342 | + * Depending on the data, it can be based on the Gedcom Header description, or from a place example. |
|
343 | + * This is returned as an associative array: |
|
344 | + * - type: describe the source of the data (<em>header<em> / <em>data</em>) |
|
345 | + * - hierarchy: an array of the place hierarchy (in reverse order of the gedcom) |
|
346 | + * |
|
347 | + * @return array |
|
348 | + */ |
|
349 | + public function getPlacesHierarchy() { |
|
350 | + if(!$this->place_hierarchy) { |
|
351 | + if($place_structure = $this->getPlacesHierarchyFromHeader()) { |
|
352 | + $this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure); |
|
353 | + } |
|
354 | + else { |
|
355 | + $this->place_hierarchy = array('type' => 'data', 'hierarchy' => $this->getPlacesHierarchyFromData()); |
|
356 | + } |
|
357 | + } |
|
358 | + return $this->place_hierarchy; |
|
359 | + } |
|
360 | 360 | |
361 | - /** |
|
362 | - * Returns an array of the place hierarchy, as defined in the GEDCOM header. |
|
363 | - * The places are reversed compared to normal GEDCOM structure. |
|
364 | - * |
|
365 | - * @return array|null |
|
366 | - */ |
|
367 | - protected function getPlacesHierarchyFromHeader() { |
|
368 | - $head = GedcomRecord::getInstance('HEAD', $this->tree); |
|
369 | - $head_place = $head->getFirstFact('PLAC'); |
|
370 | - if($head_place && $head_place_value = $head_place->getAttribute('FORM')){ |
|
371 | - return array_reverse(array_map('trim',explode(',', $head_place_value))); |
|
372 | - } |
|
373 | - return null; |
|
374 | - } |
|
361 | + /** |
|
362 | + * Returns an array of the place hierarchy, as defined in the GEDCOM header. |
|
363 | + * The places are reversed compared to normal GEDCOM structure. |
|
364 | + * |
|
365 | + * @return array|null |
|
366 | + */ |
|
367 | + protected function getPlacesHierarchyFromHeader() { |
|
368 | + $head = GedcomRecord::getInstance('HEAD', $this->tree); |
|
369 | + $head_place = $head->getFirstFact('PLAC'); |
|
370 | + if($head_place && $head_place_value = $head_place->getAttribute('FORM')){ |
|
371 | + return array_reverse(array_map('trim',explode(',', $head_place_value))); |
|
372 | + } |
|
373 | + return null; |
|
374 | + } |
|
375 | 375 | |
376 | - /** |
|
377 | - * Returns an array of the place hierarchy, based on a random example of place within the GEDCOM. |
|
378 | - * It will look for the longest hierarchy in the tree. |
|
379 | - * The places are reversed compared to normal GEDCOM structure. |
|
380 | - * |
|
381 | - * @return array |
|
382 | - */ |
|
383 | - protected function getPlacesHierarchyFromData() { |
|
384 | - $nb_levels = 0; |
|
376 | + /** |
|
377 | + * Returns an array of the place hierarchy, based on a random example of place within the GEDCOM. |
|
378 | + * It will look for the longest hierarchy in the tree. |
|
379 | + * The places are reversed compared to normal GEDCOM structure. |
|
380 | + * |
|
381 | + * @return array |
|
382 | + */ |
|
383 | + protected function getPlacesHierarchyFromData() { |
|
384 | + $nb_levels = 0; |
|
385 | 385 | |
386 | - //Select all '2 PLAC ' tags in the file and create array |
|
387 | - $places_list=array(); |
|
388 | - $ged_data = Database::prepare( |
|
389 | - 'SELECT i_gedcom AS gedcom'. |
|
390 | - ' FROM `##individuals`'. |
|
391 | - ' WHERE i_gedcom LIKE :gedcom AND i_file = :gedcom_id'. |
|
392 | - ' UNION ALL'. |
|
393 | - 'SELECT f_gedcom AS gedcom'. |
|
394 | - ' FROM `##families`'. |
|
395 | - ' WHERE f_gedcom LIKE :gedcom AND f_file = :gedcom_id' |
|
396 | - )->execute(array( |
|
397 | - 'gedcom' => '%\n2 PLAC %', |
|
398 | - 'gedcom_id' => $this->tree->getTreeId() |
|
399 | - ))->fetchOneColumn(); |
|
400 | - foreach ($ged_data as $ged_datum) { |
|
401 | - $matches = null; |
|
402 | - preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches); |
|
403 | - foreach ($matches[1] as $match) { |
|
404 | - $places_list[$match]=true; |
|
405 | - } |
|
406 | - } |
|
386 | + //Select all '2 PLAC ' tags in the file and create array |
|
387 | + $places_list=array(); |
|
388 | + $ged_data = Database::prepare( |
|
389 | + 'SELECT i_gedcom AS gedcom'. |
|
390 | + ' FROM `##individuals`'. |
|
391 | + ' WHERE i_gedcom LIKE :gedcom AND i_file = :gedcom_id'. |
|
392 | + ' UNION ALL'. |
|
393 | + 'SELECT f_gedcom AS gedcom'. |
|
394 | + ' FROM `##families`'. |
|
395 | + ' WHERE f_gedcom LIKE :gedcom AND f_file = :gedcom_id' |
|
396 | + )->execute(array( |
|
397 | + 'gedcom' => '%\n2 PLAC %', |
|
398 | + 'gedcom_id' => $this->tree->getTreeId() |
|
399 | + ))->fetchOneColumn(); |
|
400 | + foreach ($ged_data as $ged_datum) { |
|
401 | + $matches = null; |
|
402 | + preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches); |
|
403 | + foreach ($matches[1] as $match) { |
|
404 | + $places_list[$match]=true; |
|
405 | + } |
|
406 | + } |
|
407 | 407 | |
408 | - // Unique list of places |
|
409 | - $places_list=array_keys($places_list); |
|
408 | + // Unique list of places |
|
409 | + $places_list=array_keys($places_list); |
|
410 | 410 | |
411 | - //sort the array, limit to unique values, and count them |
|
412 | - usort($places_list, array('I18N', 'strcasecmp')); |
|
411 | + //sort the array, limit to unique values, and count them |
|
412 | + usort($places_list, array('I18N', 'strcasecmp')); |
|
413 | 413 | |
414 | - //calculate maximum no. of levels to display |
|
415 | - $has_found_good_example = false; |
|
416 | - foreach($places_list as $place){ |
|
417 | - $levels = explode(",", $place); |
|
418 | - $parts = count($levels); |
|
419 | - if ($parts >= $nb_levels){ |
|
420 | - $nb_levels = $parts; |
|
421 | - if(!$has_found_good_example){ |
|
422 | - $random_place = $place; |
|
423 | - if(min(array_map('strlen', $levels)) > 0){ |
|
424 | - $has_found_good_example = true; |
|
425 | - } |
|
426 | - } |
|
427 | - } |
|
428 | - } |
|
414 | + //calculate maximum no. of levels to display |
|
415 | + $has_found_good_example = false; |
|
416 | + foreach($places_list as $place){ |
|
417 | + $levels = explode(",", $place); |
|
418 | + $parts = count($levels); |
|
419 | + if ($parts >= $nb_levels){ |
|
420 | + $nb_levels = $parts; |
|
421 | + if(!$has_found_good_example){ |
|
422 | + $random_place = $place; |
|
423 | + if(min(array_map('strlen', $levels)) > 0){ |
|
424 | + $has_found_good_example = true; |
|
425 | + } |
|
426 | + } |
|
427 | + } |
|
428 | + } |
|
429 | 429 | |
430 | - return array_reverse(array_map('trim',explode(',', $random_place))); |
|
431 | - } |
|
430 | + return array_reverse(array_map('trim',explode(',', $random_place))); |
|
431 | + } |
|
432 | 432 | |
433 | - /** |
|
434 | - * Returns the list of geodispersion maps available within the maps folder. |
|
435 | - * |
|
436 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMap[] |
|
437 | - */ |
|
438 | - public function getOutlineMapsList() { |
|
439 | - $res = array(); |
|
440 | - $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'; |
|
441 | - if(is_dir($root_path)){ |
|
442 | - $dir = opendir($root_path); |
|
443 | - while (($file=readdir($dir))!== false) { |
|
444 | - if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) { |
|
445 | - $res[base64_encode($file)] = new OutlineMap($file, true); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - return $res; |
|
450 | - } |
|
433 | + /** |
|
434 | + * Returns the list of geodispersion maps available within the maps folder. |
|
435 | + * |
|
436 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMap[] |
|
437 | + */ |
|
438 | + public function getOutlineMapsList() { |
|
439 | + $res = array(); |
|
440 | + $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'; |
|
441 | + if(is_dir($root_path)){ |
|
442 | + $dir = opendir($root_path); |
|
443 | + while (($file=readdir($dir))!== false) { |
|
444 | + if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) { |
|
445 | + $res[base64_encode($file)] = new OutlineMap($file, true); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + return $res; |
|
450 | + } |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | \ No newline at end of file |
@@ -30,151 +30,151 @@ discard block |
||
30 | 30 | * Certificates Module. |
31 | 31 | */ |
32 | 32 | class CertificatesModule |
33 | - extends AbstractModule |
|
34 | - implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface, DependentInterface |
|
33 | + extends AbstractModule |
|
34 | + implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface, DependentInterface |
|
35 | 35 | { |
36 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
37 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
36 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
37 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Provider for Certificates |
|
41 | - * @var CertificateProviderInterface $provider |
|
42 | - */ |
|
43 | - protected $provider; |
|
39 | + /** |
|
40 | + * Provider for Certificates |
|
41 | + * @var CertificateProviderInterface $provider |
|
42 | + */ |
|
43 | + protected $provider; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inhericDoc} |
|
47 | - */ |
|
48 | - public function getTitle() { |
|
49 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
50 | - } |
|
45 | + /** |
|
46 | + * {@inhericDoc} |
|
47 | + */ |
|
48 | + public function getTitle() { |
|
49 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inhericDoc} |
|
54 | - */ |
|
55 | - public function getDescription() { |
|
56 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
57 | - } |
|
52 | + /** |
|
53 | + * {@inhericDoc} |
|
54 | + */ |
|
55 | + public function getDescription() { |
|
56 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inhericDoc} |
|
61 | - */ |
|
62 | - public function modAction($mod_action) { |
|
63 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
64 | - } |
|
59 | + /** |
|
60 | + * {@inhericDoc} |
|
61 | + */ |
|
62 | + public function modAction($mod_action) { |
|
63 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * {@inheritDoc} |
|
68 | - * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
69 | - */ |
|
70 | - public function validatePrerequisites() { |
|
71 | - return Functions::isEncryptionCompatible(); |
|
72 | - } |
|
66 | + /** |
|
67 | + * {@inheritDoc} |
|
68 | + * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
69 | + */ |
|
70 | + public function validatePrerequisites() { |
|
71 | + return Functions::isEncryptionCompatible(); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * {@inhericDoc} |
|
76 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
77 | - */ |
|
78 | - public function getConfigLink() { |
|
79 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
80 | - } |
|
74 | + /** |
|
75 | + * {@inhericDoc} |
|
76 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
77 | + */ |
|
78 | + public function getConfigLink() { |
|
79 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * {@inhericDoc} |
|
84 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
85 | - */ |
|
86 | - public function getSubscribedHooks() { |
|
87 | - return array( |
|
88 | - 'hFactSourcePrepend' => 50, |
|
89 | - 'hGetExpectedTags' => 50, |
|
90 | - 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
91 | - 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
92 | - 'hAddSimpleTag#SOUR' => 50, |
|
93 | - 'hHasHelpTextTag#_ACT' => 50, |
|
94 | - 'hGetHelpTextTag#_ACT' => 50 |
|
95 | - ); |
|
96 | - } |
|
82 | + /** |
|
83 | + * {@inhericDoc} |
|
84 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
85 | + */ |
|
86 | + public function getSubscribedHooks() { |
|
87 | + return array( |
|
88 | + 'hFactSourcePrepend' => 50, |
|
89 | + 'hGetExpectedTags' => 50, |
|
90 | + 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
91 | + 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
92 | + 'hAddSimpleTag#SOUR' => 50, |
|
93 | + 'hHasHelpTextTag#_ACT' => 50, |
|
94 | + 'hGetHelpTextTag#_ACT' => 50 |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * {@inhericDoc} |
|
100 | - * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
101 | - */ |
|
102 | - public function getMenu(Tree $tree, $reference = null) { |
|
103 | - $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
104 | - return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
105 | - } |
|
98 | + /** |
|
99 | + * {@inhericDoc} |
|
100 | + * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
101 | + */ |
|
102 | + public function getMenu(Tree $tree, $reference = null) { |
|
103 | + $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
104 | + return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * {@inhericDoc} |
|
109 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
110 | - */ |
|
111 | - public function hFactSourcePrepend($srec) { |
|
112 | - global $WT_TREE; |
|
107 | + /** |
|
108 | + * {@inhericDoc} |
|
109 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
110 | + */ |
|
111 | + public function hFactSourcePrepend($srec) { |
|
112 | + global $WT_TREE; |
|
113 | 113 | |
114 | - $html=''; |
|
115 | - $sid=null; |
|
114 | + $html=''; |
|
115 | + $sid=null; |
|
116 | 116 | |
117 | - if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($WT_TREE)){ |
|
118 | - if (!$srec || strlen($srec) == 0) return $html; |
|
117 | + if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($WT_TREE)){ |
|
118 | + if (!$srec || strlen($srec) == 0) return $html; |
|
119 | 119 | |
120 | - $certificate = null; |
|
121 | - $subrecords = explode("\n", $srec); |
|
122 | - $levelSOUR = substr($subrecords[0], 0, 1); |
|
123 | - $match = null; |
|
124 | - if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
125 | - $sid=$match[1]; |
|
126 | - }; |
|
127 | - $nb_subrecords = count($subrecords); |
|
128 | - for ($i=0; $i < $nb_subrecords; $i++) { |
|
129 | - $subrecords[$i] = trim($subrecords[$i]); |
|
130 | - $tag = substr($subrecords[$i], 2, 4); |
|
131 | - $text = substr($subrecords[$i], 7); |
|
132 | - if($tag == '_ACT') $certificate= new Certificate($text, $WT_TREE, $this->getProvider()); |
|
133 | - } |
|
120 | + $certificate = null; |
|
121 | + $subrecords = explode("\n", $srec); |
|
122 | + $levelSOUR = substr($subrecords[0], 0, 1); |
|
123 | + $match = null; |
|
124 | + if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
125 | + $sid=$match[1]; |
|
126 | + }; |
|
127 | + $nb_subrecords = count($subrecords); |
|
128 | + for ($i=0; $i < $nb_subrecords; $i++) { |
|
129 | + $subrecords[$i] = trim($subrecords[$i]); |
|
130 | + $tag = substr($subrecords[$i], 2, 4); |
|
131 | + $text = substr($subrecords[$i], 7); |
|
132 | + if($tag == '_ACT') $certificate= new Certificate($text, $WT_TREE, $this->getProvider()); |
|
133 | + } |
|
134 | 134 | |
135 | - if($certificate && $certificate->canShow()) |
|
136 | - $html = $this->getDisplay_ACT($certificate, $sid); |
|
135 | + if($certificate && $certificate->canShow()) |
|
136 | + $html = $this->getDisplay_ACT($certificate, $sid); |
|
137 | 137 | |
138 | - } |
|
139 | - return $html; |
|
140 | - } |
|
138 | + } |
|
139 | + return $html; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * {@inhericDoc} |
|
144 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
145 | - */ |
|
146 | - public function hFactSourceAppend($srec) { } |
|
142 | + /** |
|
143 | + * {@inhericDoc} |
|
144 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
145 | + */ |
|
146 | + public function hFactSourceAppend($srec) { } |
|
147 | 147 | |
148 | - /** |
|
149 | - * {@inhericDoc} |
|
150 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
151 | - */ |
|
152 | - public function hGetExpectedTags() { |
|
153 | - return array('SOUR' => '_ACT'); |
|
154 | - } |
|
148 | + /** |
|
149 | + * {@inhericDoc} |
|
150 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
151 | + */ |
|
152 | + public function hGetExpectedTags() { |
|
153 | + return array('SOUR' => '_ACT'); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * {@inhericDoc} |
|
158 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
159 | - */ |
|
160 | - public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
161 | - $html = ''; |
|
162 | - switch($tag){ |
|
163 | - case '_ACT': |
|
164 | - if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
165 | - break; |
|
166 | - } |
|
167 | - return $html; |
|
168 | - } |
|
156 | + /** |
|
157 | + * {@inhericDoc} |
|
158 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
159 | + */ |
|
160 | + public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
161 | + $html = ''; |
|
162 | + switch($tag){ |
|
163 | + case '_ACT': |
|
164 | + if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
165 | + break; |
|
166 | + } |
|
167 | + return $html; |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * {@inhericDoc} |
|
172 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
173 | - */ |
|
174 | - public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
175 | - global $controller, $WT_TREE; |
|
170 | + /** |
|
171 | + * {@inhericDoc} |
|
172 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
173 | + */ |
|
174 | + public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
175 | + global $controller, $WT_TREE; |
|
176 | 176 | |
177 | - $html = ''; |
|
177 | + $html = ''; |
|
178 | 178 | |
179 | 179 | switch($tag){ |
180 | 180 | case '_ACT': |
@@ -202,77 +202,77 @@ discard block |
||
202 | 202 | } |
203 | 203 | |
204 | 204 | return $html; |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * {@inhericDoc} |
|
209 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
210 | - */ |
|
211 | - public function hAddSimpleTag($context, $level) { |
|
212 | - switch($context){ |
|
213 | - case 'SOUR': |
|
214 | - FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
215 | - break; |
|
216 | - } |
|
217 | - } |
|
207 | + /** |
|
208 | + * {@inhericDoc} |
|
209 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
210 | + */ |
|
211 | + public function hAddSimpleTag($context, $level) { |
|
212 | + switch($context){ |
|
213 | + case 'SOUR': |
|
214 | + FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
215 | + break; |
|
216 | + } |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * {@inhericDoc} |
|
221 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
222 | - */ |
|
223 | - public function hHasHelpTextTag($tag) { |
|
224 | - switch($tag){ |
|
219 | + /** |
|
220 | + * {@inhericDoc} |
|
221 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
222 | + */ |
|
223 | + public function hHasHelpTextTag($tag) { |
|
224 | + switch($tag){ |
|
225 | 225 | case '_ACT': |
226 | 226 | return true; |
227 | 227 | } |
228 | 228 | return false; |
229 | - } |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * {@inhericDoc} |
|
233 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
234 | - */ |
|
235 | - public function hGetHelpTextTag($tag) { |
|
236 | - switch($tag){ |
|
237 | - case '_ACT': |
|
238 | - return array( |
|
239 | - I18N::translate('Certificate'), |
|
240 | - '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
241 | - default: |
|
242 | - return null; |
|
243 | - } |
|
244 | - } |
|
231 | + /** |
|
232 | + * {@inhericDoc} |
|
233 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
234 | + */ |
|
235 | + public function hGetHelpTextTag($tag) { |
|
236 | + switch($tag){ |
|
237 | + case '_ACT': |
|
238 | + return array( |
|
239 | + I18N::translate('Certificate'), |
|
240 | + '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
241 | + default: |
|
242 | + return null; |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Returns the default Certificate File Provider, as configured in the module |
|
248 | - * |
|
249 | - * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
250 | - */ |
|
251 | - public function getProvider() { |
|
252 | - global $WT_TREE; |
|
246 | + /** |
|
247 | + * Returns the default Certificate File Provider, as configured in the module |
|
248 | + * |
|
249 | + * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
250 | + */ |
|
251 | + public function getProvider() { |
|
252 | + global $WT_TREE; |
|
253 | 253 | |
254 | - if(!$this->provider) { |
|
255 | - $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
256 | - $this->provider = new CertificateFileProvider($root_path, $WT_TREE); |
|
257 | - } |
|
258 | - return $this->provider; |
|
259 | - } |
|
254 | + if(!$this->provider) { |
|
255 | + $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
256 | + $this->provider = new CertificateFileProvider($root_path, $WT_TREE); |
|
257 | + } |
|
258 | + return $this->provider; |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * Return the HTML code for custom simple tag _ACT |
|
264 | - * |
|
265 | - * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
266 | - * @param string|null $sid Linked Source ID, if it exists |
|
267 | - */ |
|
268 | - protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
269 | - $html = ''; |
|
270 | - if($certificate){ |
|
271 | - $certificate->setSource($sid); |
|
272 | - $html = $certificate->displayImage('icon'); |
|
273 | - } |
|
274 | - return $html; |
|
275 | - } |
|
262 | + /** |
|
263 | + * Return the HTML code for custom simple tag _ACT |
|
264 | + * |
|
265 | + * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
266 | + * @param string|null $sid Linked Source ID, if it exists |
|
267 | + */ |
|
268 | + protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
269 | + $html = ''; |
|
270 | + if($certificate){ |
|
271 | + $certificate->setSource($sid); |
|
272 | + $html = $certificate->displayImage('icon'); |
|
273 | + } |
|
274 | + return $html; |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | 278 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return boolean |
136 | 136 | */ |
137 | 137 | public static function isEncryptionCompatible() { |
138 | - return function_exists('mcrypt_encrypt') && function_exists('mcrypt_encrypt') && function_exists('mcrypt_decrypt'); |
|
138 | + return function_exists('mcrypt_encrypt') && function_exists('mcrypt_encrypt') && function_exists('mcrypt_decrypt'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @return string Encrypted and encoded text |
147 | 147 | */ |
148 | 148 | public static function encryptToSafeBase64($data){ |
149 | - if(!self::isEncryptionCompatible()) |
|
150 | - throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
149 | + if(!self::isEncryptionCompatible()) |
|
150 | + throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
151 | 151 | |
152 | 152 | $key = 'STANDARDKEYIFNOSERVER'; |
153 | 153 | if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @return string Decrypted text |
170 | 170 | */ |
171 | 171 | public static function decryptFromSafeBase64($encrypted){ |
172 | - if(!self::isEncryptionCompatible()) |
|
173 | - throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
172 | + if(!self::isEncryptionCompatible()) |
|
173 | + throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
174 | 174 | |
175 | 175 | $key = 'STANDARDKEYIFNOSERVER'; |
176 | 176 | if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public static function encodeFileSystemToUtf8($string){ |
199 | 199 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
200 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
200 | + return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
201 | 201 | } |
202 | 202 | return $string; |
203 | 203 | } |
@@ -262,20 +262,20 @@ discard block |
||
262 | 262 | * @return boolean|string Is supported? |
263 | 263 | */ |
264 | 264 | public static function isImageTypeSupported($reqtype) { |
265 | - $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
266 | - $reqtype = strtolower($reqtype); |
|
265 | + $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
266 | + $reqtype = strtolower($reqtype); |
|
267 | 267 | |
268 | - if (empty($supportByGD[$reqtype])) { |
|
269 | - return false; |
|
270 | - } |
|
268 | + if (empty($supportByGD[$reqtype])) { |
|
269 | + return false; |
|
270 | + } |
|
271 | 271 | |
272 | - $type = $supportByGD[$reqtype]; |
|
272 | + $type = $supportByGD[$reqtype]; |
|
273 | 273 | |
274 | - if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
275 | - return $type; |
|
276 | - } |
|
274 | + if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
275 | + return $type; |
|
276 | + } |
|
277 | 277 | |
278 | - return false; |
|
278 | + return false; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | } |
@@ -22,54 +22,54 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class ImageBuilder { |
24 | 24 | |
25 | - /** |
|
26 | - * Reference media |
|
27 | - * @var Media $media |
|
28 | - */ |
|
29 | - protected $media; |
|
25 | + /** |
|
26 | + * Reference media |
|
27 | + * @var Media $media |
|
28 | + */ |
|
29 | + protected $media; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Use TTF font |
|
33 | - * @var bool $use_ttf |
|
34 | - */ |
|
35 | - protected $use_ttf; |
|
31 | + /** |
|
32 | + * Use TTF font |
|
33 | + * @var bool $use_ttf |
|
34 | + */ |
|
35 | + protected $use_ttf; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Expiration offset. Default is one day. |
|
39 | - * @var int $expire_offset |
|
40 | - */ |
|
41 | - protected $expire_offset; |
|
37 | + /** |
|
38 | + * Expiration offset. Default is one day. |
|
39 | + * @var int $expire_offset |
|
40 | + */ |
|
41 | + protected $expire_offset; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Should the certificate display a watermark |
|
45 | - * @var bool $show_watermark |
|
46 | - */ |
|
47 | - protected $show_watermark; |
|
43 | + /** |
|
44 | + * Should the certificate display a watermark |
|
45 | + * @var bool $show_watermark |
|
46 | + */ |
|
47 | + protected $show_watermark; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Maximum watermark font size. Default is 18. |
|
51 | - * @var int $font_max_size |
|
52 | - */ |
|
53 | - protected $font_max_size; |
|
49 | + /** |
|
50 | + * Maximum watermark font size. Default is 18. |
|
51 | + * @var int $font_max_size |
|
52 | + */ |
|
53 | + protected $font_max_size; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Watermark font color, in hexadecimal. Default is #4D6DF3. |
|
57 | - * @var string $font_color |
|
58 | - */ |
|
59 | - protected $font_color; |
|
55 | + /** |
|
56 | + * Watermark font color, in hexadecimal. Default is #4D6DF3. |
|
57 | + * @var string $font_color |
|
58 | + */ |
|
59 | + protected $font_color; |
|
60 | 60 | |
61 | 61 | /** |
62 | - * Contructor for ImageBuilder |
|
63 | - * |
|
64 | - * @param Media|null $media Reference media object |
|
65 | - */ |
|
62 | + * Contructor for ImageBuilder |
|
63 | + * |
|
64 | + * @param Media|null $media Reference media object |
|
65 | + */ |
|
66 | 66 | public function __construct(Media $media = null){ |
67 | - $this->media = $media; |
|
68 | - $this->use_ttf = function_exists('imagettftext'); |
|
69 | - $this->expire_offset = 3600 * 24; |
|
70 | - $this->show_watermark = true; |
|
71 | - $this->font_max_size = 18; |
|
72 | - $this->font_color = '#4D6DF3'; |
|
67 | + $this->media = $media; |
|
68 | + $this->use_ttf = function_exists('imagettftext'); |
|
69 | + $this->expire_offset = 3600 * 24; |
|
70 | + $this->show_watermark = true; |
|
71 | + $this->font_max_size = 18; |
|
72 | + $this->font_color = '#4D6DF3'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return int |
79 | 79 | */ |
80 | 80 | public function getExpireOffset() { |
81 | - return $this->expire_offset; |
|
81 | + return $this->expire_offset; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @return ImageBuilder |
89 | 89 | */ |
90 | 90 | public function setExpireOffset($expireOffset) { |
91 | - if($expireOffset) $this->expire_offset = $expireOffset; |
|
92 | - return $this; |
|
91 | + if($expireOffset) $this->expire_offset = $expireOffset; |
|
92 | + return $this; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @return bool |
99 | 99 | */ |
100 | 100 | public function isShowWatermark() { |
101 | - return $this->show_watermark; |
|
101 | + return $this->show_watermark; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @return ImageBuilder |
109 | 109 | */ |
110 | 110 | public function setShowWatermark($show_watermark) { |
111 | - if(!is_null($show_watermark)) $this->show_watermark = $show_watermark; |
|
112 | - return $this; |
|
111 | + if(!is_null($show_watermark)) $this->show_watermark = $show_watermark; |
|
112 | + return $this; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @return ImageBuilder |
120 | 120 | */ |
121 | 121 | public function setFontMaxSize($font_max_size) { |
122 | - if($font_max_size) $this->font_max_size = $font_max_size; |
|
123 | - return $this; |
|
122 | + if($font_max_size) $this->font_max_size = $font_max_size; |
|
123 | + return $this; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @return ImageBuilder |
131 | 131 | */ |
132 | 132 | public function setFontColor($font_color) { |
133 | - if($font_color) $this->font_color = $font_color; |
|
134 | - return $this; |
|
133 | + if($font_color) $this->font_color = $font_color; |
|
134 | + return $this; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,134 +139,134 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function render(){ |
141 | 141 | |
142 | - if (!$this->media || !$this->media->canShow()) { |
|
143 | - Log::addMediaLog('Image Builder error: >' . I18N::translate('Missing or private media object.')); |
|
144 | - $this->renderError(); |
|
145 | - } |
|
142 | + if (!$this->media || !$this->media->canShow()) { |
|
143 | + Log::addMediaLog('Image Builder error: >' . I18N::translate('Missing or private media object.')); |
|
144 | + $this->renderError(); |
|
145 | + } |
|
146 | 146 | |
147 | - $serverFilename = $this->media->getServerFilename(); |
|
147 | + $serverFilename = $this->media->getServerFilename(); |
|
148 | 148 | |
149 | - if (!file_exists($serverFilename)) { |
|
150 | - Log::addMediaLog('Image Builder error: >'. I18N::translate('The media object does not exist.').'< for path >'.$serverFilename.'<'); |
|
151 | - $this->renderError(); |
|
152 | - } |
|
149 | + if (!file_exists($serverFilename)) { |
|
150 | + Log::addMediaLog('Image Builder error: >'. I18N::translate('The media object does not exist.').'< for path >'.$serverFilename.'<'); |
|
151 | + $this->renderError(); |
|
152 | + } |
|
153 | 153 | |
154 | - $mimetype = $this->media->mimeType(); |
|
155 | - $imgsize = $this->media->getImageAttributes(); |
|
156 | - $filetime = $this->media->getFiletime(); |
|
157 | - $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT'; |
|
158 | - $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $this->getExpireOffset()) . ' GMT'; |
|
154 | + $mimetype = $this->media->mimeType(); |
|
155 | + $imgsize = $this->media->getImageAttributes(); |
|
156 | + $filetime = $this->media->getFiletime(); |
|
157 | + $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT'; |
|
158 | + $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $this->getExpireOffset()) . ' GMT'; |
|
159 | 159 | |
160 | - $type = Functions::isImageTypeSupported($imgsize['ext']); |
|
161 | - $usewatermark = false; |
|
162 | - // if this image supports watermarks and the watermark module is intalled... |
|
163 | - if ($type) { |
|
164 | - $usewatermark = $this->isShowWatermark(); |
|
165 | - } |
|
160 | + $type = Functions::isImageTypeSupported($imgsize['ext']); |
|
161 | + $usewatermark = false; |
|
162 | + // if this image supports watermarks and the watermark module is intalled... |
|
163 | + if ($type) { |
|
164 | + $usewatermark = $this->isShowWatermark(); |
|
165 | + } |
|
166 | 166 | |
167 | - // determine whether we have enough memory to watermark this image |
|
168 | - if ($usewatermark) { |
|
169 | - if (!FunctionsMedia::hasMemoryForImage($serverFilename)) { |
|
170 | - // not enough memory to watermark this file |
|
171 | - $usewatermark = false; |
|
172 | - } |
|
173 | - } |
|
167 | + // determine whether we have enough memory to watermark this image |
|
168 | + if ($usewatermark) { |
|
169 | + if (!FunctionsMedia::hasMemoryForImage($serverFilename)) { |
|
170 | + // not enough memory to watermark this file |
|
171 | + $usewatermark = false; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - $etag = $this->media->getEtag(); |
|
175 | + $etag = $this->media->getEtag(); |
|
176 | 176 | |
177 | - // parse IF_MODIFIED_SINCE header from client |
|
178 | - $if_modified_since = 'x'; |
|
179 | - if (!empty(Filter::server('HTTP_IF_MODIFIED_SINCE'))) { |
|
180 | - $if_modified_since = preg_replace('/;.*$/', '', Filter::server('HTTP_IF_MODIFIED_SINCE')); |
|
181 | - } |
|
177 | + // parse IF_MODIFIED_SINCE header from client |
|
178 | + $if_modified_since = 'x'; |
|
179 | + if (!empty(Filter::server('HTTP_IF_MODIFIED_SINCE'))) { |
|
180 | + $if_modified_since = preg_replace('/;.*$/', '', Filter::server('HTTP_IF_MODIFIED_SINCE')); |
|
181 | + } |
|
182 | 182 | |
183 | - // parse IF_NONE_MATCH header from client |
|
184 | - $if_none_match = 'x'; |
|
185 | - if (!empty(Filter::server('HTTP_IF_NONE_MATCH'))) { |
|
186 | - $if_none_match = str_replace('"', '', Filter::server('HTTP_IF_NONE_MATCH')); |
|
187 | - } |
|
183 | + // parse IF_NONE_MATCH header from client |
|
184 | + $if_none_match = 'x'; |
|
185 | + if (!empty(Filter::server('HTTP_IF_NONE_MATCH'))) { |
|
186 | + $if_none_match = str_replace('"', '', Filter::server('HTTP_IF_NONE_MATCH')); |
|
187 | + } |
|
188 | 188 | |
189 | - // add caching headers. allow browser to cache file, but not proxy |
|
190 | - header('Last-Modified: ' . $filetimeHeader); |
|
191 | - header('ETag: "' . $etag . '"'); |
|
192 | - header('Expires: ' . $expireHeader); |
|
193 | - header('Cache-Control: max-age=' . $this->getExpireOffset() . ', s-maxage=0, proxy-revalidate'); |
|
189 | + // add caching headers. allow browser to cache file, but not proxy |
|
190 | + header('Last-Modified: ' . $filetimeHeader); |
|
191 | + header('ETag: "' . $etag . '"'); |
|
192 | + header('Expires: ' . $expireHeader); |
|
193 | + header('Cache-Control: max-age=' . $this->getExpireOffset() . ', s-maxage=0, proxy-revalidate'); |
|
194 | 194 | |
195 | - // if this file is already in the user’s cache, don’t resend it |
|
196 | - // first check if the if_modified_since param matches |
|
197 | - if ($if_modified_since === $filetimeHeader) { |
|
198 | - // then check if the etag matches |
|
199 | - if ($if_none_match === $etag) { |
|
200 | - http_response_code(304); |
|
195 | + // if this file is already in the user’s cache, don’t resend it |
|
196 | + // first check if the if_modified_since param matches |
|
197 | + if ($if_modified_since === $filetimeHeader) { |
|
198 | + // then check if the etag matches |
|
199 | + if ($if_none_match === $etag) { |
|
200 | + http_response_code(304); |
|
201 | 201 | |
202 | - return; |
|
203 | - } |
|
204 | - } |
|
202 | + return; |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - // send headers for the image |
|
207 | - header('Content-Type: ' . $mimetype); |
|
208 | - header('Content-Disposition: filename="' . addslashes(basename($this->media->getFilename())) . '"'); |
|
206 | + // send headers for the image |
|
207 | + header('Content-Type: ' . $mimetype); |
|
208 | + header('Content-Disposition: filename="' . addslashes(basename($this->media->getFilename())) . '"'); |
|
209 | 209 | |
210 | - if ($usewatermark) { |
|
211 | - // generate the watermarked image |
|
212 | - $imCreateFunc = 'imagecreatefrom' . $type; |
|
213 | - $imSendFunc = 'image' . $type; |
|
210 | + if ($usewatermark) { |
|
211 | + // generate the watermarked image |
|
212 | + $imCreateFunc = 'imagecreatefrom' . $type; |
|
213 | + $imSendFunc = 'image' . $type; |
|
214 | 214 | |
215 | - if (function_exists($imCreateFunc) && function_exists($imSendFunc)) { |
|
216 | - $im = $imCreateFunc($serverFilename); |
|
217 | - $im = $this->applyWatermark($im); |
|
215 | + if (function_exists($imCreateFunc) && function_exists($imSendFunc)) { |
|
216 | + $im = $imCreateFunc($serverFilename); |
|
217 | + $im = $this->applyWatermark($im); |
|
218 | 218 | |
219 | - // send the image |
|
220 | - $imSendFunc($im); |
|
221 | - imagedestroy($im); |
|
219 | + // send the image |
|
220 | + $imSendFunc($im); |
|
221 | + imagedestroy($im); |
|
222 | 222 | |
223 | - return; |
|
224 | - } else { |
|
225 | - // this image is defective. log it |
|
226 | - Log::addMediaLog('Image Builder error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage()); |
|
227 | - } |
|
228 | - } |
|
223 | + return; |
|
224 | + } else { |
|
225 | + // this image is defective. log it |
|
226 | + Log::addMediaLog('Image Builder error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage()); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - // determine filesize of image (could be original or watermarked version) |
|
231 | - $filesize = filesize($serverFilename); |
|
230 | + // determine filesize of image (could be original or watermarked version) |
|
231 | + $filesize = filesize($serverFilename); |
|
232 | 232 | |
233 | - // set content-length header, send file |
|
234 | - header('Content-Length: ' . $filesize); |
|
233 | + // set content-length header, send file |
|
234 | + header('Content-Length: ' . $filesize); |
|
235 | 235 | |
236 | - // Some servers disable fpassthru() and readfile() |
|
237 | - if (function_exists('readfile')) { |
|
238 | - readfile($serverFilename); |
|
239 | - } else { |
|
240 | - $fp = fopen($serverFilename, 'rb'); |
|
241 | - if (function_exists('fpassthru')) { |
|
242 | - fpassthru($fp); |
|
243 | - } else { |
|
244 | - while (!feof($fp)) { |
|
245 | - echo fread($fp, 65536); |
|
246 | - } |
|
247 | - } |
|
248 | - fclose($fp); |
|
249 | - } |
|
236 | + // Some servers disable fpassthru() and readfile() |
|
237 | + if (function_exists('readfile')) { |
|
238 | + readfile($serverFilename); |
|
239 | + } else { |
|
240 | + $fp = fopen($serverFilename, 'rb'); |
|
241 | + if (function_exists('fpassthru')) { |
|
242 | + fpassthru($fp); |
|
243 | + } else { |
|
244 | + while (!feof($fp)) { |
|
245 | + echo fread($fp, 65536); |
|
246 | + } |
|
247 | + } |
|
248 | + fclose($fp); |
|
249 | + } |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * Render an error as an image. |
254 | 254 | */ |
255 | 255 | protected function renderError() { |
256 | - $error = I18N::translate('The media file was not found in this family tree.'); |
|
256 | + $error = I18N::translate('The media file was not found in this family tree.'); |
|
257 | 257 | |
258 | - $width = (mb_strlen($error) * 6.5 + 50) * 1.15; |
|
259 | - $height = 60; |
|
260 | - $im = imagecreatetruecolor($width, $height); /* Create a black image */ |
|
261 | - $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ |
|
262 | - imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ |
|
258 | + $width = (mb_strlen($error) * 6.5 + 50) * 1.15; |
|
259 | + $height = 60; |
|
260 | + $im = imagecreatetruecolor($width, $height); /* Create a black image */ |
|
261 | + $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ |
|
262 | + imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ |
|
263 | 263 | |
264 | - $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); |
|
264 | + $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); |
|
265 | 265 | |
266 | - http_response_code(404); |
|
267 | - header('Content-Type: image/png'); |
|
268 | - imagepng($im); |
|
269 | - imagedestroy($im); |
|
266 | + http_response_code(404); |
|
267 | + header('Content-Type: image/png'); |
|
268 | + imagepng($im); |
|
269 | + imagedestroy($im); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | */ |
279 | 279 | protected function applyWatermark($im) { |
280 | 280 | |
281 | - // text to watermark with |
|
282 | - if(method_exists($this->media, 'getWatermarkText')) { |
|
283 | - $word1_text = $this->media->getWatermarkText(); |
|
284 | - } |
|
285 | - else { |
|
286 | - $word1_text = $this->media->getTitle(); |
|
287 | - } |
|
281 | + // text to watermark with |
|
282 | + if(method_exists($this->media, 'getWatermarkText')) { |
|
283 | + $word1_text = $this->media->getWatermarkText(); |
|
284 | + } |
|
285 | + else { |
|
286 | + $word1_text = $this->media->getTitle(); |
|
287 | + } |
|
288 | 288 | |
289 | - $this->embedText( |
|
290 | - $im, |
|
291 | - $word1_text, |
|
292 | - $this->font_max_size, |
|
293 | - $this->font_color, |
|
294 | - WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, |
|
295 | - 'top', |
|
296 | - 'left' |
|
297 | - ); |
|
289 | + $this->embedText( |
|
290 | + $im, |
|
291 | + $word1_text, |
|
292 | + $this->font_max_size, |
|
293 | + $this->font_color, |
|
294 | + WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, |
|
295 | + 'top', |
|
296 | + 'left' |
|
297 | + ); |
|
298 | 298 | |
299 | - return ($im); |
|
299 | + return ($im); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -313,94 +313,94 @@ discard block |
||
313 | 313 | */ |
314 | 314 | protected function embedText($im, $text, $maxsize, $color, $font, $vpos, $hpos) { |
315 | 315 | |
316 | - // there are two ways to embed text with PHP |
|
317 | - // (preferred) using GD and FreeType you can embed text using any True Type font |
|
318 | - // (fall back) if that is not available, you can insert basic monospaced text |
|
316 | + // there are two ways to embed text with PHP |
|
317 | + // (preferred) using GD and FreeType you can embed text using any True Type font |
|
318 | + // (fall back) if that is not available, you can insert basic monospaced text |
|
319 | 319 | |
320 | - $col = $this->hexrgb($color); |
|
321 | - $textcolor = imagecolorallocate($im, $col['red'], $col['green'], $col['blue']); |
|
320 | + $col = $this->hexrgb($color); |
|
321 | + $textcolor = imagecolorallocate($im, $col['red'], $col['green'], $col['blue']); |
|
322 | 322 | |
323 | - // make adjustments to settings that imagestring and imagestringup can’t handle |
|
324 | - if (!$this->use_ttf) { |
|
325 | - // imagestringup only writes up, can’t use top2bottom |
|
326 | - if ($hpos === 'top2bottom') { |
|
327 | - $hpos = 'bottom2top'; |
|
328 | - } |
|
329 | - } |
|
323 | + // make adjustments to settings that imagestring and imagestringup can’t handle |
|
324 | + if (!$this->use_ttf) { |
|
325 | + // imagestringup only writes up, can’t use top2bottom |
|
326 | + if ($hpos === 'top2bottom') { |
|
327 | + $hpos = 'bottom2top'; |
|
328 | + } |
|
329 | + } |
|
330 | 330 | |
331 | - $text = I18N::reverseText($text); |
|
332 | - $height = imagesy($im); |
|
333 | - $width = imagesx($im); |
|
334 | - $calc_angle = rad2deg(atan($height / $width)); |
|
335 | - $hypoth = $height / sin(deg2rad($calc_angle)); |
|
331 | + $text = I18N::reverseText($text); |
|
332 | + $height = imagesy($im); |
|
333 | + $width = imagesx($im); |
|
334 | + $calc_angle = rad2deg(atan($height / $width)); |
|
335 | + $hypoth = $height / sin(deg2rad($calc_angle)); |
|
336 | 336 | |
337 | - // vertical and horizontal position of the text |
|
338 | - switch ($vpos) { |
|
339 | - default: |
|
340 | - case 'top': |
|
341 | - $taille = $this->textLength($maxsize, $width, $text); |
|
342 | - $pos_y = $height * 0.15 + $taille; |
|
343 | - $pos_x = $width * 0.15; |
|
344 | - $rotation = 0; |
|
345 | - break; |
|
346 | - case 'middle': |
|
347 | - $taille = $this->textLength($maxsize, $width, $text); |
|
348 | - $pos_y = ($height + $taille) / 2; |
|
349 | - $pos_x = $width * 0.15; |
|
350 | - $rotation = 0; |
|
351 | - break; |
|
352 | - case 'bottom': |
|
353 | - $taille = $this->textLength($maxsize, $width, $text); |
|
354 | - $pos_y = ($height * .85 - $taille); |
|
355 | - $pos_x = $width * 0.15; |
|
356 | - $rotation = 0; |
|
357 | - break; |
|
358 | - case 'across': |
|
359 | - switch ($hpos) { |
|
360 | - default: |
|
361 | - case 'left': |
|
362 | - $taille = $this->textLength($maxsize, $hypoth, $text); |
|
363 | - $pos_y = ($height * .85 - $taille); |
|
364 | - $pos_x = $width * 0.15; |
|
365 | - $rotation = $calc_angle; |
|
366 | - break; |
|
367 | - case 'right': |
|
368 | - $taille = $this->textLength($maxsize, $hypoth, $text); |
|
369 | - $pos_y = ($height * .15 - $taille); |
|
370 | - $pos_x = $width * 0.85; |
|
371 | - $rotation = $calc_angle + 180; |
|
372 | - break; |
|
373 | - case 'top2bottom': |
|
374 | - $taille = $this->textLength($maxsize, $height, $text); |
|
375 | - $pos_y = ($height * .15 - $taille); |
|
376 | - $pos_x = ($width * .90 - $taille); |
|
377 | - $rotation = -90; |
|
378 | - break; |
|
379 | - case 'bottom2top': |
|
380 | - $taille = $this->textLength($maxsize, $height, $text); |
|
381 | - $pos_y = $height * 0.85; |
|
382 | - $pos_x = $width * 0.15; |
|
383 | - $rotation = 90; |
|
384 | - break; |
|
385 | - } |
|
386 | - break; |
|
387 | - } |
|
337 | + // vertical and horizontal position of the text |
|
338 | + switch ($vpos) { |
|
339 | + default: |
|
340 | + case 'top': |
|
341 | + $taille = $this->textLength($maxsize, $width, $text); |
|
342 | + $pos_y = $height * 0.15 + $taille; |
|
343 | + $pos_x = $width * 0.15; |
|
344 | + $rotation = 0; |
|
345 | + break; |
|
346 | + case 'middle': |
|
347 | + $taille = $this->textLength($maxsize, $width, $text); |
|
348 | + $pos_y = ($height + $taille) / 2; |
|
349 | + $pos_x = $width * 0.15; |
|
350 | + $rotation = 0; |
|
351 | + break; |
|
352 | + case 'bottom': |
|
353 | + $taille = $this->textLength($maxsize, $width, $text); |
|
354 | + $pos_y = ($height * .85 - $taille); |
|
355 | + $pos_x = $width * 0.15; |
|
356 | + $rotation = 0; |
|
357 | + break; |
|
358 | + case 'across': |
|
359 | + switch ($hpos) { |
|
360 | + default: |
|
361 | + case 'left': |
|
362 | + $taille = $this->textLength($maxsize, $hypoth, $text); |
|
363 | + $pos_y = ($height * .85 - $taille); |
|
364 | + $pos_x = $width * 0.15; |
|
365 | + $rotation = $calc_angle; |
|
366 | + break; |
|
367 | + case 'right': |
|
368 | + $taille = $this->textLength($maxsize, $hypoth, $text); |
|
369 | + $pos_y = ($height * .15 - $taille); |
|
370 | + $pos_x = $width * 0.85; |
|
371 | + $rotation = $calc_angle + 180; |
|
372 | + break; |
|
373 | + case 'top2bottom': |
|
374 | + $taille = $this->textLength($maxsize, $height, $text); |
|
375 | + $pos_y = ($height * .15 - $taille); |
|
376 | + $pos_x = ($width * .90 - $taille); |
|
377 | + $rotation = -90; |
|
378 | + break; |
|
379 | + case 'bottom2top': |
|
380 | + $taille = $this->textLength($maxsize, $height, $text); |
|
381 | + $pos_y = $height * 0.85; |
|
382 | + $pos_x = $width * 0.15; |
|
383 | + $rotation = 90; |
|
384 | + break; |
|
385 | + } |
|
386 | + break; |
|
387 | + } |
|
388 | 388 | |
389 | - // apply the text |
|
390 | - if ($this->use_ttf) { |
|
391 | - // if imagettftext throws errors, catch them with a custom error handler |
|
392 | - set_error_handler(array($this, 'imageTtfTextErrorHandler')); |
|
393 | - imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text); |
|
394 | - restore_error_handler(); |
|
395 | - } |
|
396 | - // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false |
|
397 | - if (!$this->use_ttf) { |
|
398 | - if ($rotation !== 90) { |
|
399 | - imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
400 | - } else { |
|
401 | - imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
402 | - } |
|
403 | - } |
|
389 | + // apply the text |
|
390 | + if ($this->use_ttf) { |
|
391 | + // if imagettftext throws errors, catch them with a custom error handler |
|
392 | + set_error_handler(array($this, 'imageTtfTextErrorHandler')); |
|
393 | + imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text); |
|
394 | + restore_error_handler(); |
|
395 | + } |
|
396 | + // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false |
|
397 | + if (!$this->use_ttf) { |
|
398 | + if ($rotation !== 90) { |
|
399 | + imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
400 | + } else { |
|
401 | + imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
402 | + } |
|
403 | + } |
|
404 | 404 | |
405 | 405 | } |
406 | 406 | |
@@ -412,53 +412,53 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected function hexrgb ($hexstr) |
414 | 414 | { |
415 | - $int = hexdec($hexstr); |
|
415 | + $int = hexdec($hexstr); |
|
416 | 416 | |
417 | - return array('red' => 0xFF & ($int >> 0x10), |
|
418 | - 'green' => 0xFF & ($int >> 0x8), |
|
419 | - 'blue' => 0xFF & $int); |
|
417 | + return array('red' => 0xFF & ($int >> 0x10), |
|
418 | + 'green' => 0xFF & ($int >> 0x8), |
|
419 | + 'blue' => 0xFF & $int); |
|
420 | 420 | } |
421 | 421 | |
422 | - /** |
|
423 | - * Generate an approximate length of text, in pixels. |
|
424 | - * |
|
425 | - * @param int $t |
|
426 | - * @param int $mxl |
|
427 | - * @param string $text |
|
428 | - * |
|
429 | - * @return int |
|
430 | - */ |
|
431 | - function textLength($t, $mxl, $text) { |
|
432 | - $taille_c = $t; |
|
433 | - $len = mb_strlen($text); |
|
434 | - while (($taille_c - 2) * $len > $mxl) { |
|
435 | - $taille_c--; |
|
436 | - if ($taille_c == 2) { |
|
437 | - break; |
|
438 | - } |
|
439 | - } |
|
422 | + /** |
|
423 | + * Generate an approximate length of text, in pixels. |
|
424 | + * |
|
425 | + * @param int $t |
|
426 | + * @param int $mxl |
|
427 | + * @param string $text |
|
428 | + * |
|
429 | + * @return int |
|
430 | + */ |
|
431 | + function textLength($t, $mxl, $text) { |
|
432 | + $taille_c = $t; |
|
433 | + $len = mb_strlen($text); |
|
434 | + while (($taille_c - 2) * $len > $mxl) { |
|
435 | + $taille_c--; |
|
436 | + if ($taille_c == 2) { |
|
437 | + break; |
|
438 | + } |
|
439 | + } |
|
440 | 440 | |
441 | - return $taille_c; |
|
442 | - } |
|
441 | + return $taille_c; |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * imagettftext is the function that is most likely to throw an error |
|
446 | - * use this custom error handler to catch and log it |
|
447 | - * |
|
448 | - * @param int $errno |
|
449 | - * @param string $errstr |
|
450 | - * |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - function imageTtfTextErrorHandler($errno, $errstr) { |
|
454 | - // log the error |
|
455 | - Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); |
|
444 | + /** |
|
445 | + * imagettftext is the function that is most likely to throw an error |
|
446 | + * use this custom error handler to catch and log it |
|
447 | + * |
|
448 | + * @param int $errno |
|
449 | + * @param string $errstr |
|
450 | + * |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + function imageTtfTextErrorHandler($errno, $errstr) { |
|
454 | + // log the error |
|
455 | + Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); |
|
456 | 456 | |
457 | - // change value of useTTF to false so the fallback watermarking can be used. |
|
458 | - $this->use_ttf = false; |
|
457 | + // change value of useTTF to false so the fallback watermarking can be used. |
|
458 | + $this->use_ttf = false; |
|
459 | 459 | |
460 | - return true; |
|
461 | - } |
|
460 | + return true; |
|
461 | + } |
|
462 | 462 | |
463 | 463 | } |
464 | 464 |
@@ -18,35 +18,35 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Dispatcher implements DispatcherInterface { |
20 | 20 | |
21 | - /** |
|
22 | - * @var Dispatcher $instance Singleton pattern instance |
|
23 | - */ |
|
24 | - private static $instance = null; |
|
21 | + /** |
|
22 | + * @var Dispatcher $instance Singleton pattern instance |
|
23 | + */ |
|
24 | + private static $instance = null; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns the *Dispatcher* instance of this class. |
|
28 | - * |
|
29 | - * @return Dispatcher The *Singleton* instance. |
|
30 | - */ |
|
31 | - public static function getInstance() |
|
32 | - { |
|
33 | - if (null === static::$instance) { |
|
34 | - static::$instance = new static(); |
|
35 | - } |
|
26 | + /** |
|
27 | + * Returns the *Dispatcher* instance of this class. |
|
28 | + * |
|
29 | + * @return Dispatcher The *Singleton* instance. |
|
30 | + */ |
|
31 | + public static function getInstance() |
|
32 | + { |
|
33 | + if (null === static::$instance) { |
|
34 | + static::$instance = new static(); |
|
35 | + } |
|
36 | 36 | |
37 | - return static::$instance; |
|
38 | - } |
|
37 | + return static::$instance; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | /** |
41 | - * Protected constructor. |
|
42 | - */ |
|
43 | - protected function __construct() {} |
|
41 | + * Protected constructor. |
|
42 | + */ |
|
43 | + protected function __construct() {} |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc } |
|
47 | - * @see \MyArtJaub\Webtrees\Mvc\DispatcherInterface::handle() |
|
48 | - */ |
|
49 | - public function handle(fw\Module\AbstractModule $module, $request) { |
|
45 | + /** |
|
46 | + * {@inheritdoc } |
|
47 | + * @see \MyArtJaub\Webtrees\Mvc\DispatcherInterface::handle() |
|
48 | + */ |
|
49 | + public function handle(fw\Module\AbstractModule $module, $request) { |
|
50 | 50 | |
51 | 51 | $fq_modclass_name = get_class($module); |
52 | 52 | $ctrl_namespace = substr($fq_modclass_name, 0, - strlen('Module')) . '\\'; |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | |
67 | 67 | $ctrl_class = $ctrl_namespace . $ctrl_name . 'Controller'; |
68 | 68 | if(class_exists($ctrl_class) |
69 | - && is_subclass_of($ctrl_class, '\\MyArtJaub\\Webtrees\\Mvc\\Controller\\MvcController') |
|
69 | + && is_subclass_of($ctrl_class, '\\MyArtJaub\\Webtrees\\Mvc\\Controller\\MvcController') |
|
70 | 70 | && $ctrl = new $ctrl_class($module) ) { |
71 | 71 | if(method_exists($ctrl, $method)) { |
72 | - try { |
|
73 | - call_user_func_array(array($ctrl, $method), array()); |
|
74 | - } |
|
75 | - catch (MvcException $ex) { |
|
76 | - if(!headers_sent()) { |
|
77 | - http_response_code($ex->getHttpCode()); |
|
78 | - } |
|
79 | - echo $ex->getMessage(); |
|
80 | - } |
|
72 | + try { |
|
73 | + call_user_func_array(array($ctrl, $method), array()); |
|
74 | + } |
|
75 | + catch (MvcException $ex) { |
|
76 | + if(!headers_sent()) { |
|
77 | + http_response_code($ex->getHttpCode()); |
|
78 | + } |
|
79 | + echo $ex->getMessage(); |
|
80 | + } |
|
81 | 81 | } |
82 | 82 | else { |
83 | 83 | throw new \Exception('The page requested does not exist'); |
@@ -86,27 +86,27 @@ discard block |
||
86 | 86 | else { |
87 | 87 | throw new \Exception('The page requested does not exist'); |
88 | 88 | } |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Private clone method to prevent cloning of the instance of the |
|
93 | - * *Dispatcher* instance. |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - private function __clone() |
|
98 | - { |
|
99 | - } |
|
91 | + /** |
|
92 | + * Private clone method to prevent cloning of the instance of the |
|
93 | + * *Dispatcher* instance. |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + private function __clone() |
|
98 | + { |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Private unserialize method to prevent unserializing of the *Dispatcher* |
|
103 | - * instance. |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - private function __wakeup() |
|
108 | - { |
|
109 | - } |
|
101 | + /** |
|
102 | + * Private unserialize method to prevent unserializing of the *Dispatcher* |
|
103 | + * instance. |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + private function __wakeup() |
|
108 | + { |
|
109 | + } |
|
110 | 110 | |
111 | 111 | } |
112 | 112 |
@@ -16,52 +16,52 @@ |
||
16 | 16 | */ |
17 | 17 | class MvcException extends \Exception { |
18 | 18 | |
19 | - /** @var int[] $VALID_HTTP List of valid HTTP codes */ |
|
20 | - protected static $VALID_HTTP = array( |
|
21 | - 100, 101, |
|
22 | - 200, 201, 202, 203, 204, 205, 206, |
|
23 | - 300, 301, 302, 303, 304, 305, 306, 307, |
|
24 | - 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, |
|
25 | - 500, 501, 502, 503, 504, 505 |
|
26 | - ); |
|
19 | + /** @var int[] $VALID_HTTP List of valid HTTP codes */ |
|
20 | + protected static $VALID_HTTP = array( |
|
21 | + 100, 101, |
|
22 | + 200, 201, 202, 203, 204, 205, 206, |
|
23 | + 300, 301, 302, 303, 304, 305, 306, 307, |
|
24 | + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, |
|
25 | + 500, 501, 502, 503, 504, 505 |
|
26 | + ); |
|
27 | 27 | |
28 | - /** @var int $http_code */ |
|
29 | - protected $http_code; |
|
28 | + /** @var int $http_code */ |
|
29 | + protected $http_code; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor for MvcException |
|
33 | - * |
|
34 | - * @param int $http_code |
|
35 | - * @param string $message |
|
36 | - * @param int $code |
|
37 | - * @param \Throwable $previous |
|
38 | - */ |
|
39 | - public function __construct($http_code = 500, $message = "", $code = 0, \Throwable $previous = null) { |
|
40 | - parent::__construct($message, $code, $previous); |
|
31 | + /** |
|
32 | + * Constructor for MvcException |
|
33 | + * |
|
34 | + * @param int $http_code |
|
35 | + * @param string $message |
|
36 | + * @param int $code |
|
37 | + * @param \Throwable $previous |
|
38 | + */ |
|
39 | + public function __construct($http_code = 500, $message = "", $code = 0, \Throwable $previous = null) { |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | 41 | |
42 | - $this->http_code = in_array($http_code, self::$VALID_HTTP) ? $http_code : 500; |
|
43 | - } |
|
42 | + $this->http_code = in_array($http_code, self::$VALID_HTTP) ? $http_code : 500; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the HTTP code |
|
47 | - * |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function getHttpCode() { |
|
51 | - return $this->http_code; |
|
52 | - } |
|
45 | + /** |
|
46 | + * Get the HTTP code |
|
47 | + * |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function getHttpCode() { |
|
51 | + return $this->http_code; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Set the HTTP code |
|
56 | - * |
|
57 | - * @param int $http_code |
|
58 | - * @throws InvalidArgumentException Thrown if not valid Http code |
|
59 | - */ |
|
60 | - public function setHttpCode($http_code) { |
|
61 | - if(!in_array($http_code, self::$VALID_HTTP)) |
|
62 | - throw new \InvalidArgumentException('Invalid HTTP code'); |
|
63 | - $this->http_code= $http_code; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Set the HTTP code |
|
56 | + * |
|
57 | + * @param int $http_code |
|
58 | + * @throws InvalidArgumentException Thrown if not valid Http code |
|
59 | + */ |
|
60 | + public function setHttpCode($http_code) { |
|
61 | + if(!in_array($http_code, self::$VALID_HTTP)) |
|
62 | + throw new \InvalidArgumentException('Invalid HTTP code'); |
|
63 | + $this->http_code= $http_code; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
67 | 67 |
@@ -19,59 +19,59 @@ |
||
19 | 19 | * Hooks Module. |
20 | 20 | */ |
21 | 21 | class HooksModule extends AbstractModule implements ModuleConfigInterface, DependentInterface { |
22 | - // How to update the database schema for this module |
|
23 | - const SCHEMA_TARGET_VERSION = 1; |
|
24 | - const SCHEMA_SETTING_NAME = 'MAJ_HOOKS_SCHEMA_VERSION'; |
|
25 | - const SCHEMA_MIGRATION_PREFIX = '\MyArtJaub\Webtrees\Module\Hooks\Schema'; |
|
22 | + // How to update the database schema for this module |
|
23 | + const SCHEMA_TARGET_VERSION = 1; |
|
24 | + const SCHEMA_SETTING_NAME = 'MAJ_HOOKS_SCHEMA_VERSION'; |
|
25 | + const SCHEMA_MIGRATION_PREFIX = '\MyArtJaub\Webtrees\Module\Hooks\Schema'; |
|
26 | 26 | |
27 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
28 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
27 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
28 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inhericDoc} |
|
32 | - */ |
|
33 | - public function getTitle() { |
|
34 | - return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks'); |
|
35 | - } |
|
30 | + /** |
|
31 | + * {@inhericDoc} |
|
32 | + */ |
|
33 | + public function getTitle() { |
|
34 | + return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks'); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * {@inhericDoc} |
|
39 | - */ |
|
40 | - public function getDescription() { |
|
41 | - return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.'); |
|
42 | - } |
|
37 | + /** |
|
38 | + * {@inhericDoc} |
|
39 | + */ |
|
40 | + public function getDescription() { |
|
41 | + return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.'); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * {@inhericDoc} |
|
46 | - */ |
|
47 | - public function modAction($mod_action) { |
|
48 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
44 | + /** |
|
45 | + * {@inhericDoc} |
|
46 | + */ |
|
47 | + public function modAction($mod_action) { |
|
48 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
49 | 49 | |
50 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
51 | - } |
|
50 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inhericDoc} |
|
55 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
56 | - */ |
|
57 | - public function getConfigLink() { |
|
58 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
53 | + /** |
|
54 | + * {@inhericDoc} |
|
55 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
56 | + */ |
|
57 | + public function getConfigLink() { |
|
58 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
59 | 59 | |
60 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
61 | - } |
|
60 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritDoc} |
|
65 | - * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
66 | - */ |
|
67 | - public function validatePrerequisites() { |
|
68 | - try { |
|
69 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
70 | - return true; |
|
71 | - } |
|
72 | - catch (\Exception $ex) { } |
|
73 | - return false; |
|
74 | - } |
|
63 | + /** |
|
64 | + * {@inheritDoc} |
|
65 | + * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
66 | + */ |
|
67 | + public function validatePrerequisites() { |
|
68 | + try { |
|
69 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
70 | + return true; |
|
71 | + } |
|
72 | + catch (\Exception $ex) { } |
|
73 | + return false; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | 77 | } |
@@ -28,30 +28,30 @@ discard block |
||
28 | 28 | class WelcomeBlockController extends MvcController |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Pages |
|
33 | - */ |
|
31 | + /** |
|
32 | + * Pages |
|
33 | + */ |
|
34 | 34 | |
35 | - /** |
|
36 | - * WelcomeBlock@index |
|
37 | - * |
|
38 | - * @param PageController $parent_controller |
|
39 | - * @param Tree $tree |
|
40 | - * @param string $block_id |
|
41 | - * @param string $template |
|
42 | - * @return $string |
|
43 | - */ |
|
44 | - public function index(PageController $parent_controller, Tree $tree, $block_id, $template) { |
|
45 | - $view_bag = new ViewBag(); |
|
35 | + /** |
|
36 | + * WelcomeBlock@index |
|
37 | + * |
|
38 | + * @param PageController $parent_controller |
|
39 | + * @param Tree $tree |
|
40 | + * @param string $block_id |
|
41 | + * @param string $template |
|
42 | + * @return $string |
|
43 | + */ |
|
44 | + public function index(PageController $parent_controller, Tree $tree, $block_id, $template) { |
|
45 | + $view_bag = new ViewBag(); |
|
46 | 46 | |
47 | - if($parent_controller && $tree) { |
|
47 | + if($parent_controller && $tree) { |
|
48 | 48 | |
49 | - $view_bag->set('tree', $tree); |
|
50 | - $view_bag->set('indi', $parent_controller->getSignificantIndividual()); |
|
49 | + $view_bag->set('tree', $tree); |
|
50 | + $view_bag->set('indi', $parent_controller->getSignificantIndividual()); |
|
51 | 51 | |
52 | - $id = $this->module->getName().$block_id; |
|
53 | - $class = $this->module->getName().'_block'; |
|
54 | - $parent_controller->addInlineJavascript(' |
|
52 | + $id = $this->module->getName().$block_id; |
|
53 | + $class = $this->module->getName().'_block'; |
|
54 | + $parent_controller->addInlineJavascript(' |
|
55 | 55 | jQuery("#maj-new_passwd").hide(); |
56 | 56 | jQuery("#maj-passwd_click").click(function() |
57 | 57 | { |
@@ -62,62 +62,62 @@ discard block |
||
62 | 62 | }); |
63 | 63 | '); |
64 | 64 | |
65 | - if (Auth::isAdmin()) { |
|
66 | - $title='<a class="icon-admin" title="'.I18N::translate('Configure').'" href="block_edit.php?block_id='.$block_id.'&ged=' . $tree->getNameHtml() . '&ctype=gedcom"></a>'; |
|
67 | - } else { |
|
68 | - $title=''; |
|
69 | - } |
|
70 | - $title .='<span dir="auto">'.$tree->getTitleHtml().'</span>'; |
|
65 | + if (Auth::isAdmin()) { |
|
66 | + $title='<a class="icon-admin" title="'.I18N::translate('Configure').'" href="block_edit.php?block_id='.$block_id.'&ged=' . $tree->getNameHtml() . '&ctype=gedcom"></a>'; |
|
67 | + } else { |
|
68 | + $title=''; |
|
69 | + } |
|
70 | + $title .='<span dir="auto">'.$tree->getTitleHtml().'</span>'; |
|
71 | 71 | |
72 | - $piwik_enabled = $this->module->getBlockSetting($block_id, 'piwik_enabled', false); |
|
73 | - $view_bag->set('piwik_enabled', $piwik_enabled); |
|
74 | - if($piwik_enabled) { |
|
75 | - $parent_controller->addInlineJavascript( |
|
76 | - '$("#piwik_stats") |
|
72 | + $piwik_enabled = $this->module->getBlockSetting($block_id, 'piwik_enabled', false); |
|
73 | + $view_bag->set('piwik_enabled', $piwik_enabled); |
|
74 | + if($piwik_enabled) { |
|
75 | + $parent_controller->addInlineJavascript( |
|
76 | + '$("#piwik_stats") |
|
77 | 77 | .load("module.php?mod='.$this->module->getName().'&mod_action=Piwik&block_id='.$block_id.'");' |
78 | - ); |
|
79 | - } |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - $content = ViewFactory::make('WelcomeBlock', $this, new BaseController(), $view_bag)->getHtmlPartial(); |
|
81 | + $content = ViewFactory::make('WelcomeBlock', $this, new BaseController(), $view_bag)->getHtmlPartial(); |
|
82 | 82 | |
83 | - if ($template) { |
|
84 | - return Theme::theme()->formatBlock($id, $title, $class, $content); |
|
85 | - } else { |
|
86 | - return $content; |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
83 | + if ($template) { |
|
84 | + return Theme::theme()->formatBlock($id, $title, $class, $content); |
|
85 | + } else { |
|
86 | + return $content; |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * WelcomeBlock@config |
|
95 | - * |
|
96 | - * @param string $block_id |
|
97 | - */ |
|
98 | - public function config($block_id) { |
|
93 | + /** |
|
94 | + * WelcomeBlock@config |
|
95 | + * |
|
96 | + * @param string $block_id |
|
97 | + */ |
|
98 | + public function config($block_id) { |
|
99 | 99 | |
100 | - if (Filter::postBool('save') && Filter::checkCsrf()) { |
|
101 | - $this->module->setBlockSetting($block_id, 'piwik_enabled', Filter::postBool('piwik_enabled')); |
|
102 | - $this->module->setBlockSetting($block_id, 'piwik_url', trim(Filter::postUrl('piwik_url'))); |
|
103 | - $this->module->setBlockSetting($block_id, 'piwik_siteid', trim(Filter::post('piwik_siteid'))); |
|
104 | - $this->module->setBlockSetting($block_id, 'piwik_token', trim(Filter::post('piwik_token'))); |
|
105 | - throw new MvcException(200); // Use this instead of exit |
|
106 | - } |
|
100 | + if (Filter::postBool('save') && Filter::checkCsrf()) { |
|
101 | + $this->module->setBlockSetting($block_id, 'piwik_enabled', Filter::postBool('piwik_enabled')); |
|
102 | + $this->module->setBlockSetting($block_id, 'piwik_url', trim(Filter::postUrl('piwik_url'))); |
|
103 | + $this->module->setBlockSetting($block_id, 'piwik_siteid', trim(Filter::post('piwik_siteid'))); |
|
104 | + $this->module->setBlockSetting($block_id, 'piwik_token', trim(Filter::post('piwik_token'))); |
|
105 | + throw new MvcException(200); // Use this instead of exit |
|
106 | + } |
|
107 | 107 | |
108 | - $view_bag = new ViewBag(); |
|
108 | + $view_bag = new ViewBag(); |
|
109 | 109 | |
110 | - // Is Piwik Statistic Enabled ? |
|
111 | - $view_bag->set('piwik_enabled', $this->module->getBlockSetting($block_id, 'piwik_enabled', '0')); |
|
112 | - //Piwik Root Url |
|
113 | - $view_bag->set('piwik_url', $this->module->getBlockSetting($block_id, 'piwik_url', '')); |
|
114 | - // Piwik token |
|
115 | - $view_bag->set('piwik_token', $this->module->getBlockSetting($block_id, 'piwik_token', '')); |
|
116 | - // Piwik side id |
|
117 | - $view_bag->set('piwik_siteid', $this->module->getBlockSetting($block_id, 'piwik_siteid', '')); |
|
110 | + // Is Piwik Statistic Enabled ? |
|
111 | + $view_bag->set('piwik_enabled', $this->module->getBlockSetting($block_id, 'piwik_enabled', '0')); |
|
112 | + //Piwik Root Url |
|
113 | + $view_bag->set('piwik_url', $this->module->getBlockSetting($block_id, 'piwik_url', '')); |
|
114 | + // Piwik token |
|
115 | + $view_bag->set('piwik_token', $this->module->getBlockSetting($block_id, 'piwik_token', '')); |
|
116 | + // Piwik side id |
|
117 | + $view_bag->set('piwik_siteid', $this->module->getBlockSetting($block_id, 'piwik_siteid', '')); |
|
118 | 118 | |
119 | - ViewFactory::make('WelcomeBlockConfig', $this, new BaseController(), $view_bag)->renderPartial(); |
|
120 | - } |
|
119 | + ViewFactory::make('WelcomeBlockConfig', $this, new BaseController(), $view_bag)->renderPartial(); |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | 123 |