@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @param integer $num Numerator |
| 53 | 53 | * @param integer $denom Denominator |
| 54 | - * @param float $default Default value if denominator null or 0 |
|
| 55 | - * @return float Result of the safe division |
|
| 54 | + * @param integer $default Default value if denominator null or 0 |
|
| 55 | + * @return integer Result of the safe division |
|
| 56 | 56 | */ |
| 57 | 57 | public static function safeDivision($num, $denom, $default = 0) { |
| 58 | 58 | if($denom && $denom!=0){ |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @param int $num Numerator |
| 68 | 68 | * @param int $denom Denominator |
| 69 | - * @param float $default Default value if denominator null or 0 |
|
| 70 | - * @return float Percentage |
|
| 69 | + * @param integer $default Default value if denominator null or 0 |
|
| 70 | + * @return integer Percentage |
|
| 71 | 71 | */ |
| 72 | 72 | public static function getPercentage($num, $denom, $default = 0){ |
| 73 | 73 | return 100 * self::safeDivision($num, $denom, $default); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param string $file The image to resize |
| 80 | 80 | * @param int $target The final max width/height |
| 81 | - * @return array array of ($width, $height). One of them must be $target |
|
| 81 | + * @return integer[] array of ($width, $height). One of them must be $target |
|
| 82 | 82 | */ |
| 83 | 83 | static public function getResizedImageSize($file, $target=25){ |
| 84 | 84 | list($width, $height, $type, $attr) = getimagesize($file); |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * Returns the generation associated with a Sosa number |
| 234 | 234 | * |
| 235 | 235 | * @param int $sosa Sosa number |
| 236 | - * @return number |
|
| 236 | + * @return integer |
|
| 237 | 237 | */ |
| 238 | 238 | public static function getGeneration($sosa){ |
| 239 | 239 | return(int)log($sosa, 2)+1; |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * Returns whether the image type is supported by the system, and if so, return the standardised type |
| 247 | 247 | * |
| 248 | 248 | * @param string $reqtype Extension to test |
| 249 | - * @return boolean|string Is supported? |
|
| 249 | + * @return false|string Is supported? |
|
| 250 | 250 | */ |
| 251 | 251 | public static function isImageTypeSupported($reqtype) { |
| 252 | 252 | $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param string $text Text to display |
| 40 | 40 | */ |
| 41 | - static public function promptAlert($text){ |
|
| 41 | + static public function promptAlert($text) { |
|
| 42 | 42 | echo '<script>'; |
| 43 | - echo 'alert("',fw\Filter::escapeHtml($text),'")'; |
|
| 43 | + echo 'alert("', fw\Filter::escapeHtml($text), '")'; |
|
| 44 | 44 | echo '</script>'; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return float Result of the safe division |
| 54 | 54 | */ |
| 55 | 55 | public static function safeDivision($num, $denom, $default = 0) { |
| 56 | - if($denom && $denom!=0){ |
|
| 56 | + if ($denom && $denom != 0) { |
|
| 57 | 57 | return $num / $denom; |
| 58 | 58 | } |
| 59 | 59 | return $default; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param float $default Default value if denominator null or 0 |
| 68 | 68 | * @return float Percentage |
| 69 | 69 | */ |
| 70 | - public static function getPercentage($num, $denom, $default = 0){ |
|
| 70 | + public static function getPercentage($num, $denom, $default = 0) { |
|
| 71 | 71 | return 100 * self::safeDivision($num, $denom, $default); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * @param int $target The final max width/height |
| 79 | 79 | * @return array array of ($width, $height). One of them must be $target |
| 80 | 80 | */ |
| 81 | - static public function getResizedImageSize($file, $target=25){ |
|
| 82 | - list($width, $height, , ) = getimagesize($file); |
|
| 81 | + static public function getResizedImageSize($file, $target = 25) { |
|
| 82 | + list($width, $height,,) = getimagesize($file); |
|
| 83 | 83 | $max = max($width, $height); |
| 84 | 84 | $rapp = $target / $max; |
| 85 | 85 | $width = intval($rapp * $width); |
@@ -109,21 +109,21 @@ discard block |
||
| 109 | 109 | * @param int $length Length of the token, default to 32 |
| 110 | 110 | * @return string Random token |
| 111 | 111 | */ |
| 112 | - public static function generateRandomToken($length=32) { |
|
| 112 | + public static function generateRandomToken($length = 32) { |
|
| 113 | 113 | $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
| 114 | 114 | $len_chars = count($chars); |
| 115 | 115 | $token = ''; |
| 116 | 116 | |
| 117 | 117 | for ($i = 0; $i < $length; $i++) |
| 118 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
| 118 | + $token .= $chars[mt_rand(0, $len_chars - 1)]; |
|
| 119 | 119 | |
| 120 | 120 | # Number of 32 char chunks |
| 121 | - $chunks = ceil( strlen($token) / 32 ); |
|
| 121 | + $chunks = ceil(strlen($token) / 32); |
|
| 122 | 122 | $md5token = ''; |
| 123 | 123 | |
| 124 | 124 | # Run each chunk through md5 |
| 125 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
| 126 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
| 125 | + for ($i = 1; $i <= $chunks; $i++) |
|
| 126 | + $md5token .= md5(substr($token, $i * 32 - 32, 32)); |
|
| 127 | 127 | |
| 128 | 128 | # Trim the token |
| 129 | 129 | return substr($md5token, 0, $length); |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | * @param string $data Text to encrypt |
| 137 | 137 | * @return string Encrypted and encoded text |
| 138 | 138 | */ |
| 139 | - public static function encryptToSafeBase64($data){ |
|
| 139 | + public static function encryptToSafeBase64($data) { |
|
| 140 | 140 | $key = 'STANDARDKEYIFNOSERVER'; |
| 141 | - if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
|
| 141 | + if (Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
|
| 142 | 142 | $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
| 143 | 143 | $iv = mcrypt_create_iv(self::ENCRYPTION_IV_SIZE, MCRYPT_RAND); |
| 144 | - $id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC,$iv); |
|
| 144 | + $id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv); |
|
| 145 | 145 | $encrypted = base64_encode($iv.$id); |
| 146 | 146 | // +, / and = are not URL-compatible |
| 147 | 147 | $encrypted = str_replace('+', '-', $encrypted); |
@@ -156,22 +156,22 @@ discard block |
||
| 156 | 156 | * @param string $encrypted Text to decrypt |
| 157 | 157 | * @return string Decrypted text |
| 158 | 158 | */ |
| 159 | - public static function decryptFromSafeBase64($encrypted){ |
|
| 159 | + public static function decryptFromSafeBase64($encrypted) { |
|
| 160 | 160 | $key = 'STANDARDKEYIFNOSERVER'; |
| 161 | - if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
|
| 161 | + if (Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
|
| 162 | 162 | $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
| 163 | 163 | $encrypted = str_replace('-', '+', $encrypted); |
| 164 | 164 | $encrypted = str_replace('_', '/', $encrypted); |
| 165 | 165 | $encrypted = str_replace('*', '=', $encrypted); |
| 166 | 166 | $encrypted = base64_decode($encrypted); |
| 167 | - if(!$encrypted) |
|
| 167 | + if (!$encrypted) |
|
| 168 | 168 | throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
| 169 | - if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) |
|
| 169 | + if (strlen($encrypted) < self::ENCRYPTION_IV_SIZE) |
|
| 170 | 170 | throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
| 171 | 171 | $iv_dec = substr($encrypted, 0, self::ENCRYPTION_IV_SIZE); |
| 172 | 172 | $encrypted = substr($encrypted, self::ENCRYPTION_IV_SIZE); |
| 173 | 173 | $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv_dec); |
| 174 | - return preg_replace('~(?:\\000+)$~','',$decrypted); |
|
| 174 | + return preg_replace('~(?:\\000+)$~', '', $decrypted); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | * @param string $string Filesystem encoded string to encode |
| 181 | 181 | * @return string UTF-8 encoded string |
| 182 | 182 | */ |
| 183 | - public static function encodeFileSystemToUtf8($string){ |
|
| 183 | + public static function encodeFileSystemToUtf8($string) { |
|
| 184 | 184 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
| 185 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
| 185 | + return iconv('cp1252', 'utf-8//IGNORE', $string); |
|
| 186 | 186 | } |
| 187 | 187 | return $string; |
| 188 | 188 | } |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | * @param string $string UTF-8 encoded string to encode |
| 194 | 194 | * @return string Filesystem encoded string |
| 195 | 195 | */ |
| 196 | - public static function encodeUtf8ToFileSystem($string){ |
|
| 196 | + public static function encodeUtf8ToFileSystem($string) { |
|
| 197 | 197 | if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
| 198 | - return iconv('utf-8', 'cp1252//IGNORE' , $string); |
|
| 198 | + return iconv('utf-8', 'cp1252//IGNORE', $string); |
|
| 199 | 199 | } |
| 200 | 200 | return $string; |
| 201 | 201 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @return boolean True if path valid |
| 209 | 209 | */ |
| 210 | 210 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
| 211 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
| 211 | + if (strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
| 212 | 212 | return false; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @return array Array of month short names |
| 221 | 221 | */ |
| 222 | 222 | public static function getCalendarShortMonths($calendarId = 0) { |
| 223 | - if(!isset(self::$calendarShortMonths[$calendarId])) { |
|
| 223 | + if (!isset(self::$calendarShortMonths[$calendarId])) { |
|
| 224 | 224 | $calendar_info = cal_info($calendarId); |
| 225 | 225 | self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths']; |
| 226 | 226 | } |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param int $sosa Sosa number |
| 234 | 234 | * @return number |
| 235 | 235 | */ |
| 236 | - public static function getGeneration($sosa){ |
|
| 237 | - return(int)log($sosa, 2)+1; |
|
| 236 | + public static function getGeneration($sosa) { |
|
| 237 | + return(int)log($sosa, 2) + 1; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -114,16 +114,18 @@ discard block |
||
| 114 | 114 | $len_chars = count($chars); |
| 115 | 115 | $token = ''; |
| 116 | 116 | |
| 117 | - for ($i = 0; $i < $length; $i++) |
|
| 118 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
| 117 | + for ($i = 0; $i < $length; $i++) { |
|
| 118 | + $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
| 119 | + } |
|
| 119 | 120 | |
| 120 | 121 | # Number of 32 char chunks |
| 121 | 122 | $chunks = ceil( strlen($token) / 32 ); |
| 122 | 123 | $md5token = ''; |
| 123 | 124 | |
| 124 | 125 | # Run each chunk through md5 |
| 125 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
| 126 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
| 126 | + for ( $i=1; $i<=$chunks; $i++ ) { |
|
| 127 | + $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
| 128 | + } |
|
| 127 | 129 | |
| 128 | 130 | # Trim the token |
| 129 | 131 | return substr($md5token, 0, $length); |
@@ -138,8 +140,9 @@ discard block |
||
| 138 | 140 | */ |
| 139 | 141 | public static function encryptToSafeBase64($data){ |
| 140 | 142 | $key = 'STANDARDKEYIFNOSERVER'; |
| 141 | - if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
|
| 142 | - $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
| 143 | + if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) { |
|
| 144 | + $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
| 145 | + } |
|
| 143 | 146 | $iv = mcrypt_create_iv(self::ENCRYPTION_IV_SIZE, MCRYPT_RAND); |
| 144 | 147 | $id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC,$iv); |
| 145 | 148 | $encrypted = base64_encode($iv.$id); |
@@ -158,16 +161,19 @@ discard block |
||
| 158 | 161 | */ |
| 159 | 162 | public static function decryptFromSafeBase64($encrypted){ |
| 160 | 163 | $key = 'STANDARDKEYIFNOSERVER'; |
| 161 | - if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
|
| 162 | - $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
| 164 | + if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) { |
|
| 165 | + $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
| 166 | + } |
|
| 163 | 167 | $encrypted = str_replace('-', '+', $encrypted); |
| 164 | 168 | $encrypted = str_replace('_', '/', $encrypted); |
| 165 | 169 | $encrypted = str_replace('*', '=', $encrypted); |
| 166 | 170 | $encrypted = base64_decode($encrypted); |
| 167 | - if(!$encrypted) |
|
| 168 | - throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
|
| 169 | - if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) |
|
| 170 | - throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
| 171 | + if(!$encrypted) { |
|
| 172 | + throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
|
| 173 | + } |
|
| 174 | + if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) { |
|
| 175 | + throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
| 176 | + } |
|
| 171 | 177 | $iv_dec = substr($encrypted, 0, self::ENCRYPTION_IV_SIZE); |
| 172 | 178 | $encrypted = substr($encrypted, self::ENCRYPTION_IV_SIZE); |
| 173 | 179 | $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv_dec); |
@@ -208,7 +214,9 @@ discard block |
||
| 208 | 214 | * @return boolean True if path valid |
| 209 | 215 | */ |
| 210 | 216 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
| 211 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
| 217 | + if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) { |
|
| 218 | + return true; |
|
| 219 | + } |
|
| 212 | 220 | return false; |
| 213 | 221 | } |
| 214 | 222 | |
@@ -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 |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | ->setUsingFlags($row['majgd_useflagsgen'] == 'yes') |
| 66 | 66 | ->setMaxDetailsInGen($row['majgd_detailsgen']); |
| 67 | 67 | |
| 68 | - if($row['majgd_map']) { |
|
| 68 | + if ($row['majgd_map']) { |
|
| 69 | 69 | $options |
| 70 | 70 | ->setMap(new OutlineMap($row['majgd_map'])) |
| 71 | 71 | ->setMapLevel($row['majgd_toplevel']); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $enabled = true; |
| 75 | - if(isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') { |
|
| 75 | + if (isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') { |
|
| 76 | 76 | $enabled = false; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function getGeoAnalysisCount() { |
| 95 | 95 | return Database::prepare( |
| 96 | - 'SELECT COUNT(majgd_id)' . |
|
| 97 | - ' FROM `##maj_geodispersion`' . |
|
| 96 | + 'SELECT COUNT(majgd_id)'. |
|
| 97 | + ' FROM `##maj_geodispersion`'. |
|
| 98 | 98 | ' WHERE majgd_file = :gedcom_id' |
| 99 | 99 | )->execute(array( |
| 100 | 100 | 'gedcom_id' => $this->tree->getTreeId() |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis|NULL |
| 111 | 111 | */ |
| 112 | 112 | public function getGeoAnalysis($id, $only_enabled = true) { |
| 113 | - $args = array ( |
|
| 113 | + $args = array( |
|
| 114 | 114 | 'gedcom_id' => $this->tree->getTreeId(), |
| 115 | 115 | 'ga_id' => $id |
| 116 | 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`' . |
|
| 118 | + $sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status'. |
|
| 119 | + ' FROM `##maj_geodispersion`'. |
|
| 120 | 120 | ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'; |
| 121 | - if($only_enabled) { |
|
| 121 | + if ($only_enabled) { |
|
| 122 | 122 | $sql .= ' AND majgd_status = :status'; |
| 123 | 123 | $args['status'] = 'enabled'; |
| 124 | 124 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | $ga_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC); |
| 128 | 128 | |
| 129 | - if($ga_array) { |
|
| 129 | + if ($ga_array) { |
|
| 130 | 130 | return $this->loadGeoAnalysisFromRow($ga_array); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @return GeoAnalysis |
| 147 | 147 | */ |
| 148 | 148 | public function createGeoAnalysis($description, $analysis_level, $map_file, $map_top_level, $use_flags, $gen_details) { |
| 149 | - try{ |
|
| 149 | + try { |
|
| 150 | 150 | Database::beginTransaction(); |
| 151 | 151 | |
| 152 | 152 | Database::prepare( |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | Database::commit(); |
| 170 | 170 | } |
| 171 | - catch(\Exception $ex) { |
|
| 171 | + catch (\Exception $ex) { |
|
| 172 | 172 | Database::rollback(); |
| 173 | 173 | $ga = null; |
| 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()); |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | Database::commit(); |
| 213 | 213 | } |
| 214 | - catch(\Exception $ex) { |
|
| 214 | + catch (\Exception $ex) { |
|
| 215 | 215 | Database::rollback(); |
| 216 | - Log::addErrorLog('The Geo Analysis ID “' . $ga->getId() . '” failed to be updated. Transaction rollbacked. Exception: '.$ex->getMessage()); |
|
| 216 | + Log::addErrorLog('The Geo Analysis ID “'.$ga->getId().'” failed to be updated. Transaction rollbacked. Exception: '.$ex->getMessage()); |
|
| 217 | 217 | $ga = null; |
| 218 | 218 | } |
| 219 | 219 | return $ga; |
@@ -258,12 +258,12 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @return array List of enabled maps |
| 260 | 260 | */ |
| 261 | - public function getGeoAnalysisList(){ |
|
| 261 | + public function getGeoAnalysisList() { |
|
| 262 | 262 | $res = array(); |
| 263 | 263 | |
| 264 | 264 | $list = Database::prepare( |
| 265 | - 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen' . |
|
| 266 | - ' FROM `##maj_geodispersion`' . |
|
| 265 | + 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen'. |
|
| 266 | + ' FROM `##maj_geodispersion`'. |
|
| 267 | 267 | ' WHERE majgd_file = :gedcom_id AND majgd_status = :status'. |
| 268 | 268 | ' ORDER BY majgd_descr' |
| 269 | 269 | )->execute(array( |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | 'status' => 'enabled' |
| 272 | 272 | ))->fetchAll(\PDO::FETCH_ASSOC); |
| 273 | 273 | |
| 274 | - foreach($list as $ga) { |
|
| 274 | + foreach ($list as $ga) { |
|
| 275 | 275 | $res[] = $this->loadGeoAnalysisFromRow($ga); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -287,17 +287,17 @@ discard block |
||
| 287 | 287 | * @param int|null $limit Max number of items to return (for pagination) |
| 288 | 288 | * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
| 289 | 289 | */ |
| 290 | - public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null){ |
|
| 290 | + public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null) { |
|
| 291 | 291 | $res = array(); |
| 292 | 292 | |
| 293 | 293 | $sql = |
| 294 | - 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' . |
|
| 295 | - ' FROM `##maj_geodispersion`' . |
|
| 294 | + 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status'. |
|
| 295 | + ' FROM `##maj_geodispersion`'. |
|
| 296 | 296 | ' WHERE majgd_file = :gedcom_id'; |
| 297 | 297 | |
| 298 | 298 | $args = array('gedcom_id'=> $this->tree->getTreeId()); |
| 299 | 299 | |
| 300 | - if($search) { |
|
| 300 | + if ($search) { |
|
| 301 | 301 | $sql .= ' AND majgd_descr LIKE CONCAT(\'%\', :search, \'%\')'; |
| 302 | 302 | $args['search'] = $search; |
| 303 | 303 | } |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | switch ($value['dir']) { |
| 313 | 313 | case 'asc': |
| 314 | - $sql .= $value['column'] . ' ASC '; |
|
| 314 | + $sql .= $value['column'].' ASC '; |
|
| 315 | 315 | break; |
| 316 | 316 | case 'desc': |
| 317 | - $sql .= $value['column'] . ' DESC '; |
|
| 317 | + $sql .= $value['column'].' DESC '; |
|
| 318 | 318 | break; |
| 319 | 319 | } |
| 320 | 320 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | |
| 331 | 331 | $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC); |
| 332 | 332 | |
| 333 | - foreach($data as $ga) { |
|
| 333 | + foreach ($data as $ga) { |
|
| 334 | 334 | $res[] = $this->loadGeoAnalysisFromRow($ga); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * @return array |
| 348 | 348 | */ |
| 349 | 349 | public function getPlacesHierarchy() { |
| 350 | - if(!$this->place_hierarchy) { |
|
| 351 | - if($place_structure = $this->getPlacesHierarchyFromHeader()) { |
|
| 350 | + if (!$this->place_hierarchy) { |
|
| 351 | + if ($place_structure = $this->getPlacesHierarchyFromHeader()) { |
|
| 352 | 352 | $this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure); |
| 353 | 353 | } |
| 354 | 354 | else { |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | protected function getPlacesHierarchyFromHeader() { |
| 368 | 368 | $head = GedcomRecord::getInstance('HEAD', $this->tree); |
| 369 | 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))); |
|
| 370 | + if ($head_place && $head_place_value = $head_place->getAttribute('FORM')) { |
|
| 371 | + return array_reverse(array_map('trim', explode(',', $head_place_value))); |
|
| 372 | 372 | } |
| 373 | 373 | return null; |
| 374 | 374 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $nb_levels = 0; |
| 385 | 385 | |
| 386 | 386 | //Select all '2 PLAC ' tags in the file and create array |
| 387 | - $places_list=array(); |
|
| 387 | + $places_list = array(); |
|
| 388 | 388 | $ged_data = Database::prepare( |
| 389 | 389 | 'SELECT i_gedcom AS gedcom'. |
| 390 | 390 | ' FROM `##individuals`'. |
@@ -401,33 +401,33 @@ discard block |
||
| 401 | 401 | $matches = null; |
| 402 | 402 | preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches); |
| 403 | 403 | foreach ($matches[1] as $match) { |
| 404 | - $places_list[$match]=true; |
|
| 404 | + $places_list[$match] = true; |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // Unique list of places |
| 409 | - $places_list=array_keys($places_list); |
|
| 409 | + $places_list = array_keys($places_list); |
|
| 410 | 410 | |
| 411 | 411 | //sort the array, limit to unique values, and count them |
| 412 | 412 | usort($places_list, array('I18N', 'strcasecmp')); |
| 413 | 413 | |
| 414 | 414 | //calculate maximum no. of levels to display |
| 415 | 415 | $has_found_good_example = false; |
| 416 | - foreach($places_list as $place){ |
|
| 416 | + foreach ($places_list as $place) { |
|
| 417 | 417 | $levels = explode(",", $place); |
| 418 | 418 | $parts = count($levels); |
| 419 | - if ($parts >= $nb_levels){ |
|
| 419 | + if ($parts >= $nb_levels) { |
|
| 420 | 420 | $nb_levels = $parts; |
| 421 | - if(!$has_found_good_example){ |
|
| 421 | + if (!$has_found_good_example) { |
|
| 422 | 422 | $random_place = $place; |
| 423 | - if(min(array_map('strlen', $levels)) > 0){ |
|
| 423 | + if (min(array_map('strlen', $levels)) > 0) { |
|
| 424 | 424 | $has_found_good_example = true; |
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - return array_reverse(array_map('trim',explode(',', $random_place))); |
|
| 430 | + return array_reverse(array_map('trim', explode(',', $random_place))); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -438,9 +438,9 @@ discard block |
||
| 438 | 438 | public function getOutlineMapsList() { |
| 439 | 439 | $res = array(); |
| 440 | 440 | $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'; |
| 441 | - if(is_dir($root_path)){ |
|
| 441 | + if (is_dir($root_path)) { |
|
| 442 | 442 | $dir = opendir($root_path); |
| 443 | - while (($file=readdir($dir))!== false) { |
|
| 443 | + while (($file = readdir($dir)) !== false) { |
|
| 444 | 444 | if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) { |
| 445 | 445 | $res[base64_encode($file)] = new OutlineMap($file, true); |
| 446 | 446 | } |
@@ -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 | |