Completed
Push — feature/code-analysis ( ddc57d...5519b1 )
by Jonathan
09:07 queued 04:56
created
src/Webtrees/Module/GeoDispersion/Model/GeoAnalysisProvider.php 1 patch
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -21,130 +21,130 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Webtrees/ImageBuilder.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -22,54 +22,54 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.