| Total Complexity | 40 |
| Total Lines | 556 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Complex classes like addressbook_hooks often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use addressbook_hooks, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class addressbook_hooks |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * hooks to build projectmanager's sidebox-menu plus the admin and preferences sections |
||
| 26 | * |
||
| 27 | * @param string/array $args hook args |
||
|
|
|||
| 28 | */ |
||
| 29 | static function all_hooks($args) |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * populates $settings for the Api\Preferences |
||
| 107 | * |
||
| 108 | * @param array|string $hook_data |
||
| 109 | * @return array |
||
| 110 | */ |
||
| 111 | static function settings($hook_data) |
||
| 112 | { |
||
| 113 | $settings = array( |
||
| 114 | array( |
||
| 115 | 'type' => 'section', |
||
| 116 | 'title' => lang('General settings'), |
||
| 117 | 'no_lang'=> true, |
||
| 118 | 'xmlrpc' => False, |
||
| 119 | 'admin' => False |
||
| 120 | ), |
||
| 121 | ); |
||
| 122 | $settings['add_default'] = array( |
||
| 123 | 'type' => 'select', |
||
| 124 | 'label' => 'Default addressbook for adding contacts', |
||
| 125 | 'name' => 'add_default', |
||
| 126 | 'help' => 'Which addressbook should be selected when adding a contact AND you have no add rights to the current addressbook.', |
||
| 127 | 'values' => !$hook_data['setup'] ? ExecMethod('addressbook.addressbook_ui.get_addressbooks',Acl::ADD) : array(), |
||
| 128 | 'xmlrpc' => True, |
||
| 129 | 'admin' => False, |
||
| 130 | ); |
||
| 131 | if ($GLOBALS['egw_info']['server']['contact_repository'] != 'ldap') |
||
| 132 | { |
||
| 133 | $settings['private_addressbook'] = array( |
||
| 134 | 'type' => 'check', |
||
| 135 | 'label' => 'Enable an extra private addressbook', |
||
| 136 | 'name' => 'private_addressbook', |
||
| 137 | 'help' => 'Do you want a private addressbook, which can not be viewed by users, you grant access to your personal addressbook?', |
||
| 138 | 'xmlrpc' => True, |
||
| 139 | 'admin' => False, |
||
| 140 | 'forced' => false, |
||
| 141 | ); |
||
| 142 | } |
||
| 143 | $settings['hide_accounts'] = array( |
||
| 144 | 'type' => 'select', |
||
| 145 | 'values' => array('1' => lang('Hide all accounts'), '0' => lang('Show active accounts'), 'none' => lang('Show all accounts')), |
||
| 146 | 'label' => 'Hide accounts from addressbook', |
||
| 147 | 'name' => 'hide_accounts', |
||
| 148 | 'help' => 'Hides accounts completly from the adressbook.', |
||
| 149 | 'xmlrpc' => True, |
||
| 150 | 'admin' => false, |
||
| 151 | 'default'=> '0' |
||
| 152 | ); |
||
| 153 | $settings['hide_groups_as_lists'] = array( |
||
| 154 | 'type' => 'check', |
||
| 155 | 'label' => 'Hide user groups as distribution lists', |
||
| 156 | 'name' => 'hide_groups_as_lists', |
||
| 157 | 'help' => 'User groups are automatically shown as distribution lists.', |
||
| 158 | 'xmlrpc' => False, |
||
| 159 | 'admin' => false, |
||
| 160 | 'default'=> '0' |
||
| 161 | ); |
||
| 162 | $contacts = new Api\Contacts(); |
||
| 163 | $fileas_options = $contacts->fileas_options(); |
||
| 164 | foreach(Api\Contacts\Storage::$duplicate_fields as $key => $label) |
||
| 165 | { |
||
| 166 | $duplicate_options[$key] = lang($label); |
||
| 167 | } |
||
| 168 | |||
| 169 | $settings['link_title'] = array( |
||
| 170 | 'type' => 'select', |
||
| 171 | 'label' => 'Link title for contacts show', |
||
| 172 | 'name' => 'link_title', |
||
| 173 | 'values' => array( |
||
| 174 | 'n_fileas' => lang('own sorting').' ('.lang('default').': '.lang('Company').': '.lang('lastname').', '.lang('firstname').')', |
||
| 175 | )+$fileas_options, // plus all fileas types |
||
| 176 | 'help' => 'What should links to the addressbook display in other applications. Empty values will be left out. You need to log in anew, if you change this setting!', |
||
| 177 | 'xmlrpc' => True, |
||
| 178 | 'admin' => false, |
||
| 179 | 'default'=> 'org_name: n_family, n_given', |
||
| 180 | ); |
||
| 181 | if (($cf_opts = Api\Contacts::cf_options())) |
||
| 182 | { |
||
| 183 | $settings['link_title_cf'] = array( |
||
| 184 | 'type' => 'multiselect', |
||
| 185 | 'label' => 'Add a customfield to link title', |
||
| 186 | 'name' => 'link_title_cf', |
||
| 187 | 'values' => $cf_opts, |
||
| 188 | 'help' => 'Add customfield to links of addressbook, which displays in other applications. The default value is none customfield.', |
||
| 189 | 'xmlrpc' => True, |
||
| 190 | 'admin' => false, |
||
| 191 | ); |
||
| 192 | } |
||
| 193 | $settings['addr_format'] = array( |
||
| 194 | 'type' => 'select', |
||
| 195 | 'label' => 'Default address format', |
||
| 196 | 'name' => 'addr_format', |
||
| 197 | 'values' => array( |
||
| 198 | 'postcode_city' => lang('zip code').' '.lang('City'), |
||
| 199 | 'city_state_postcode' => lang('City').' '.lang('State').' '.lang('zip code'), |
||
| 200 | ), |
||
| 201 | 'help' => 'Which address format should the addressbook use for countries it does not know the address format. If the address format of a country is known, it uses it independent of this setting.', |
||
| 202 | 'xmlrpc' => True, |
||
| 203 | 'admin' => false, |
||
| 204 | 'default'=> 'postcode_city', |
||
| 205 | ); |
||
| 206 | $settings['fileas_default'] = array( |
||
| 207 | 'type' => 'select', |
||
| 208 | 'label' => 'Default file as format', |
||
| 209 | 'name' => 'fileas_default', |
||
| 210 | 'values' => $fileas_options, |
||
| 211 | 'help' => 'Default format for fileas, eg. for new entries.', |
||
| 212 | 'xmlrpc' => True, |
||
| 213 | 'admin' => false, |
||
| 214 | 'default'=> 'org_name: n_family, n_given', |
||
| 215 | ); |
||
| 216 | $settings['duplicate_fields'] = array( |
||
| 217 | 'type' => 'multiselect', |
||
| 218 | 'label' => 'Fields to check for duplicates', |
||
| 219 | 'name' => 'duplicate_fields', |
||
| 220 | 'values' => $duplicate_options, |
||
| 221 | 'help' => 'Fields to consider when looking for duplicate contacts.', |
||
| 222 | 'admin' => false, |
||
| 223 | 'default' => 'n_family,org_name,contact_email' |
||
| 224 | ); |
||
| 225 | $settings['duplicate_threshold'] = array( |
||
| 226 | 'type' => 'input', |
||
| 227 | 'size' => 5, |
||
| 228 | 'label' => 'Duplicate threshold', |
||
| 229 | 'name' => 'duplicate_threshold', |
||
| 230 | 'help' => 'How many fields must match for the record to be considered a duplicate.', |
||
| 231 | 'xmlrpc' => True, |
||
| 232 | 'default'=> 3, |
||
| 233 | 'admin' => False |
||
| 234 | ); |
||
| 235 | |||
| 236 | $crm_list_options = array( |
||
| 237 | '~edit~' => lang('Edit contact'), |
||
| 238 | 'infolog' => lang('Open %1 CRM view', lang('infolog')), |
||
| 239 | 'infolog-organisation' => lang('infolog-organisation'), |
||
| 240 | ); |
||
| 241 | if($GLOBALS['egw_info']['user']['apps']['tracker']) |
||
| 242 | { |
||
| 243 | $crm_list_options['tracker'] = lang('Open %1 CRM view', lang('tracker')); |
||
| 244 | } |
||
| 245 | $settings['crm_list'] = array( |
||
| 246 | 'type' => 'select', |
||
| 247 | 'label' => 'Default action on double-click', |
||
| 248 | 'name' => 'crm_list', |
||
| 249 | 'values' => $crm_list_options, |
||
| 250 | 'help' => 'When viewing a contact, show linked entries from the selected application', |
||
| 251 | 'xmlrpc' => True, |
||
| 252 | 'admin' => false, |
||
| 253 | 'default'=> 'infolog', |
||
| 254 | ); |
||
| 255 | |||
| 256 | $settings['geolocation_src'] = array( |
||
| 257 | 'type' => 'select', |
||
| 258 | 'label' => 'Default GeoLocation source address', |
||
| 259 | 'name' => 'geolocation_src', |
||
| 260 | 'values' => array( |
||
| 261 | 'browser' => lang('Browser location'), |
||
| 262 | 'one' => lang('Business address'), |
||
| 263 | 'two' => lang('Private address') |
||
| 264 | ), |
||
| 265 | 'help' => 'Select a source address to be used in GeoLocation routing system', |
||
| 266 | 'xmlrpc' => True, |
||
| 267 | 'admin' => false, |
||
| 268 | 'default'=> 'browser', |
||
| 269 | ); |
||
| 270 | |||
| 271 | $settings[] = array( |
||
| 272 | 'type' => 'section', |
||
| 273 | 'title' => lang('Data exchange settings'), |
||
| 274 | 'no_lang'=> true, |
||
| 275 | 'xmlrpc' => False, |
||
| 276 | 'admin' => False |
||
| 277 | ); |
||
| 278 | // CSV Export |
||
| 279 | |||
| 280 | if ($GLOBALS['egw_info']['user']['apps']['filemanager']) |
||
| 281 | { |
||
| 282 | $settings['default_document'] = array( |
||
| 283 | 'type' => 'vfs_file', |
||
| 284 | 'size' => 60, |
||
| 285 | 'label' => 'Default document to insert contacts', |
||
| 286 | 'name' => 'default_document', |
||
| 287 | 'help' => lang('If you specify a document (full vfs path) here, %1 displays an extra document icon for each entry. That icon allows to download the specified document with the data inserted.', lang('addressbook')).' '. |
||
| 288 | lang('The document can contain placeholder like {{%1}}, to be replaced with the data.','n_fn').' '. |
||
| 289 | lang('The following document-types are supported:'). implode(',',Api\Storage\Merge::get_file_extensions()), |
||
| 290 | 'run_lang' => false, |
||
| 291 | 'xmlrpc' => True, |
||
| 292 | 'admin' => False, |
||
| 293 | ); |
||
| 294 | $settings['document_dir'] = array( |
||
| 295 | 'type' => 'vfs_dirs', |
||
| 296 | 'size' => 60, |
||
| 297 | 'label' => 'Directory with documents to insert contacts', |
||
| 298 | 'name' => 'document_dir', |
||
| 299 | 'help' => lang('If you specify a directory (full vfs path) here, %1 displays an action for each document. That action allows to download the specified document with the data inserted.',lang('addressbook')).' '. |
||
| 300 | lang('The document can contain placeholder like {{%1}}, to be replaced with the data.','n_fn').' '. |
||
| 301 | lang('The following document-types are supported:'). implode(',',Api\Storage\Merge::get_file_extensions()), |
||
| 302 | 'run_lang' => false, |
||
| 303 | 'xmlrpc' => True, |
||
| 304 | 'admin' => False, |
||
| 305 | 'default' => '/templates/addressbook', |
||
| 306 | ); |
||
| 307 | } |
||
| 308 | |||
| 309 | if ($GLOBALS['egw_info']['user']['apps']['felamimail'] || $GLOBALS['egw_info']['user']['apps']['mail']) |
||
| 310 | { |
||
| 311 | $settings['force_mailto'] = array( |
||
| 312 | 'type' => 'check', |
||
| 313 | 'label' => 'Open EMail addresses in external mail program', |
||
| 314 | 'name' => 'force_mailto', |
||
| 315 | 'help' => 'Default is to open EMail addresses in EGroupware EMail application, if user has access to it.', |
||
| 316 | 'xmlrpc' => True, |
||
| 317 | 'admin' => False, |
||
| 318 | 'default'=> false, |
||
| 319 | ); |
||
| 320 | } |
||
| 321 | |||
| 322 | // Import / Export for nextmatch |
||
| 323 | if ($GLOBALS['egw_info']['user']['apps']['importexport']) |
||
| 324 | { |
||
| 325 | $settings['vcard_charset'] = array( |
||
| 326 | 'type' => 'select', |
||
| 327 | 'label' => 'Charset for the vCard import and export', |
||
| 328 | 'name' => 'vcard_charset', |
||
| 329 | 'values' => Api\Translation::get_installed_charsets(), |
||
| 330 | 'help' => 'Which charset should be used for the vCard import and export.', |
||
| 331 | 'xmlrpc' => True, |
||
| 332 | 'admin' => false, |
||
| 333 | 'default'=> 'utf-8', |
||
| 334 | ); |
||
| 335 | } |
||
| 336 | return $settings; |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Hook called by link-class to include calendar in the appregistry of the linkage |
||
| 341 | * |
||
| 342 | * @param array/string $location location and other parameters (not used) |
||
| 343 | * @return array with method-names |
||
| 344 | */ |
||
| 345 | static function search_link($location) |
||
| 346 | { |
||
| 347 | unset($location); // not used, but required by function signature |
||
| 348 | |||
| 349 | $links = array( |
||
| 350 | 'query' => 'api.EGroupware\\Api\\Contacts.link_query', |
||
| 351 | 'title' => 'api.EGroupware\\Api\\Contacts.link_title', |
||
| 352 | 'titles' => 'api.EGroupware\\Api\\Contacts.link_titles', |
||
| 353 | 'view' => array( |
||
| 354 | 'menuaction' => 'addressbook.addressbook_ui.view', |
||
| 355 | 'ajax' => 'true' |
||
| 356 | ), |
||
| 357 | 'view_id' => 'contact_id', |
||
| 358 | 'list' => array( |
||
| 359 | 'menuaction' => 'addressbook.addressbook_ui.index', |
||
| 360 | 'ajax' => 'true' |
||
| 361 | ), |
||
| 362 | 'edit' => array( |
||
| 363 | 'menuaction' => 'addressbook.addressbook_ui.edit' |
||
| 364 | ), |
||
| 365 | 'edit_id' => 'contact_id', |
||
| 366 | 'edit_popup' => '870x610', |
||
| 367 | 'add' => array( |
||
| 368 | 'menuaction' => 'addressbook.addressbook_ui.edit' |
||
| 369 | ), |
||
| 370 | 'add_app' => 'link_app', |
||
| 371 | 'add_id' => 'link_id', |
||
| 372 | 'add_popup' => '870x610', |
||
| 373 | 'file_access_user' => true, // file_access supports 4th parameter $user |
||
| 374 | 'file_access'=> 'api.EGroupware\\Api\\Contacts.file_access', |
||
| 375 | 'default_types' => array('n' => array('name' => 'contact', 'options' => array('icon' => 'navbar.png','template' => 'addressbook.edit'))), |
||
| 376 | // registers an addtional type 'addressbook-email', returning only contacts with email, title has email appended |
||
| 377 | 'additional' => array( |
||
| 378 | 'addressbook-email' => array( |
||
| 379 | 'query' => 'api.EGroupware\\Api\\Contacts.link_query_email', |
||
| 380 | 'view' => array( |
||
| 381 | 'menuaction' => 'addressbook.addressbook_ui.view', |
||
| 382 | 'ajax' => 'true' |
||
| 383 | ), |
||
| 384 | 'view_id' => 'contact_id', |
||
| 385 | ), |
||
| 386 | ), |
||
| 387 | 'merge' => true, |
||
| 388 | 'entry' => 'Contact', |
||
| 389 | 'entries' => 'Contacts', |
||
| 390 | 'modification_time' => array( |
||
| 391 | 'key' => 'contact_id', |
||
| 392 | 'column' => 'egw_addressbook.contact_modified', |
||
| 393 | 'type' => 'int' |
||
| 394 | ), |
||
| 395 | 'owner' => array( |
||
| 396 | 'key' => 'egw_addressbook.contact_id', |
||
| 397 | 'column' => 'egw_addressbook.contact_owner' |
||
| 398 | ) |
||
| 399 | ); |
||
| 400 | return $links; |
||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Hook called to retrieve a app specific exportLimit |
||
| 405 | * |
||
| 406 | * @param array/string $location location and other parameters (not used) |
||
| 407 | * @return the export_limit to be applied for the app, may be empty, int or string |
||
| 408 | */ |
||
| 409 | static function getAppExportLimit($location) |
||
| 410 | { |
||
| 411 | unset($location); // not used, but required by function signature |
||
| 412 | |||
| 413 | return $GLOBALS['egw_info']['server']['contact_export_limit']; |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Register contacts as calendar resources (items which can be sheduled by the calendar) |
||
| 418 | * |
||
| 419 | * @param array $args hook-params (not used) |
||
| 420 | * @return array |
||
| 421 | */ |
||
| 422 | static function calendar_resources($args) |
||
| 423 | { |
||
| 424 | unset($args); // not used, but required by function signature |
||
| 425 | |||
| 426 | return array( |
||
| 427 | 'type' => 'c',// one char type-identifiy for this resources |
||
| 428 | 'info' => 'api.EGroupware\\Api\\Contacts.calendar_info',// info method, returns array with id, type & name for a given id |
||
| 429 | ); |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Register addressbook for group-acl |
||
| 434 | * |
||
| 435 | * @param array $args hook-params (not used) |
||
| 436 | * @return boolean|string true=standard group acl link, of string with link |
||
| 437 | */ |
||
| 438 | static function group_acl($args) |
||
| 439 | { |
||
| 440 | unset($args); // not used, but required by function signature |
||
| 441 | |||
| 442 | // addressbook uses group-acl, only if contacts-backend is NOT LDAP, as the ACL can not be modified there |
||
| 443 | return $GLOBALS['egw_info']['server']['contact_repository'] != 'ldap'; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * For which groups should no group acl be used: addressbook always |
||
| 448 | * |
||
| 449 | * @param string|array $data |
||
| 450 | * @return boolean|array true, false or array with group-account_id's |
||
| 451 | */ |
||
| 452 | static function not_enum_group_acls($data) |
||
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * ACL rights and labels used |
||
| 461 | * |
||
| 462 | * @param string|array string with location or array with parameters incl. "location", specially "owner" for selected Acl owner |
||
| 463 | * @return array Acl::(READ|ADD|EDIT|DELETE|PRIVAT|CUSTOM(1|2|3)) => $label pairs |
||
| 464 | */ |
||
| 465 | public static function acl_rights($params) |
||
| 474 | ); |
||
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Hook to tell framework we use standard categories method |
||
| 479 | * |
||
| 480 | * @param string|array $data hook-data or location |
||
| 481 | * @return boolean |
||
| 482 | */ |
||
| 483 | public static function categories($data) |
||
| 488 | } |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Called before displaying site configuration |
||
| 492 | * |
||
| 493 | * @param array $config |
||
| 494 | * @return array with additional config to merge and "sel_options" values |
||
| 495 | */ |
||
| 496 | public static function config(array $config) |
||
| 578 | } |
||
| 579 | } |
||
| 580 |