'Active Directory Settings', 'ad_employee_list_prefs' => 'List Preferences', 'ad_employee_list_output_opts' => 'List Output Settings' ); /** * Build the object * @uses active_directory_employee_list::__construct() */ function __construct() { if( ! $this->_is_ldap_supported() ) { add_action( 'admin_notices', array( $this, '_ldap_not_supported' ) ); add_action( 'network_admin_notices', array( $this, '_ldap_not_supported' ) ); return; } parent::__construct(); $this->_is_multinetwork(); if( is_network_admin() && $this->is_multinetwork && 1 == $GLOBALS['current_site']->id ) { $this->_is_primary_network = true; if( 'sites.php?page=' . $this->settings_page === basename( $_SERVER['REQUEST_URI'] ) ) { $this->_is_mn_settings_page = true; } else { $page = $this->settings_page; foreach( array( $this->settings_name, $this->prefs_name, $this->output_name ) as $id ) { $id = 'meta-' . $id; add_filter( "postbox_classes_{$page}_{$id}", array( &$this, 'close_metabox' ), 1, 1 ); } } } if( empty( $this->_available_fields ) ) $this->_available_fields = $this->get_template_tags( false ); add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_init', array( &$this, '_init_admin' ) ); add_action( 'add_site_option', array( $this, 'maybe_delete_site_option' ), 99, 2 ); /*add_action( 'add_option', array( $this, 'maybe_delete_option' ), 99, 2 );*/ add_action( 'update_site_option', array( $this, 'maybe_delete_site_option' ), 99, 2 ); /*add_action( 'update_option', array( $this, 'maybe_delete_option' ), 99, 2 );*/ if( isset( $_REQUEST['page'] ) && $this->settings_page == $_REQUEST['page'] ) { if( ( !is_network_admin() && is_multisite() && is_plugin_active_for_network( 'active-directory-employee-list/active-directory-employee-list.php' ) ) || ( $this->is_multinetwork && !$this->_is_mn_settings_page ) ) { add_action( ( is_network_admin() ? 'network_admin_notices' : 'admin_notices' ), array( $this, 'options_override_message' ) ); } /** * Move this out of __construct() in order to avoid deprecated notices */ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts_and_styles' ) ); } } /* __construct() */ function admin_enqueue_scripts_and_styles() { wp_enqueue_script( 'ad-employee-list-admin' ); wp_enqueue_style( 'ad-employee-list-admin-style' ); } function _is_ldap_supported() { return apply_filters( 'adel-is-ldap-supported', function_exists( 'ldap_connect' ) ); } /** * Print an Admin Notice about lack of LDAP Support */ function _ldap_not_supported() { echo '
' . __( 'LDAP Not Supported', $this->text_domain ) . '
' . sprintf( __( 'Your PHP configuration does not appear to support LDAP connections; therefore, the %s plug-in will not work at all. It is recommended that you deactivate the plug-in until you are able to update your PHP configuration to support LDAP.', $this->text_domain ), $this->plugin_name ) . '
' . __( 'More information', $this->text_domain ) . '
'; echo ''; } } protected function _get_settings_fields( $group='all' ) { $fields = array( $this->settings_name => array( '_domain_controllers' => __( 'Domain controllers:', $this->text_domain ), '_base_dn' => __( 'Base DN:', $this->text_domain ), '_use_ssl' => __( 'Use an SSL connection?', $this->text_domain ), '_use_tls' => __( 'Use TLS after binding to LDAP?', $this->text_domain ), '_ad_port' => __( 'Port on which Active Directory listens:', $this->text_domain ), '_ad_username' => __( 'Bind user:', $this->text_domain ), '_ad_password' => __( 'Bind user password:', $this->text_domain ), '_account_suffix' => __( 'Account suffix for bind user:', $this->text_domain ), 'always_ignore' => __( 'Additional query information:', $this->text_domain ), ), $this->prefs_name => array( 'ad_group' => __( 'The Active Directory group(s) to retrieve:', $this->text_domain ), '_available_fields' => __( 'Which AD fields should be available in the list below?', $this->text_domain ), 'fields_to_show' => __( 'Which AD fields should be displayed in the list?', $this->text_domain ), 'results_per_page' => __( 'How many results should be shown on a page?', $this->text_domain ), 'order_by' => __( 'Sort the list according to which field?', $this->text_domain ), ), $this->output_name => array( 'before_list' => __( 'Before the employee list:', $this->text_domain ), 'after_list' => __( 'After the employee list:', $this->text_domain ), 'after_title' => __( 'After the list title:', $this->text_domain ), 'title_wrap' => __( 'HTML element to wrap the list title:', $this->text_domain ), 'title_class' => __( 'The list title CSS class:', $this->text_domain ), 'title_id' => __( 'The HTML ID for the list title:', $this->text_domain ), 'title' => __( 'The list title:', $this->text_domain ), 'list_wrap' => __( 'HTML element to wrap the list:', $this->text_domain ), 'list_class' => __( 'The list CSS class:', $this->text_domain ), 'list_id' => __( 'The HTML ID for the list:', $this->text_domain ), 'item_wrap' => __( 'The HTML element to wrap each list item:', $this->text_domain ), 'item_class' => __( 'The CSS class for each list item:', $this->text_domain ), 'item_id' => __( 'The HTML ID for each list item:', $this->text_domain ), 'prev_page_link' => __( 'Previous page link:', $this->text_domain ), 'next_page_link' => __( 'Next page link:', $this->text_domain ), 'output_builder' => __( 'List item output builder:', $this->text_domain ), ), ); return 'all' === $group ? $fields : $fields[$group]; } /** * Retrieve information about the fields being displayed */ protected function _get_field_details( $field ) { $this->_get_options(); if( empty( $this->_settings_fields ) ) { $template_tags = $this->get_template_tags( false ); foreach( $template_tags as $k=>$v ) { $template_tags[$k] = $k . ': ' . $v; } $ignore_text = sprintf( __( 'Check this box if you would like the %s settings for this options group to override any settings entered here.', $this->text_domain ), ( is_network_admin() ? 'multi-network' : 'network' ) ); $this->_settings_fields = array( 'ignore_settings_group' => array( 'note' => $ignore_text, 'type' => 'checkbox', 'default' => $this->_are_settings_empty( $this->settings_name) ? false : 1, ), 'ignore_prefs_group' => array( 'note' => $ignore_text, 'type' => 'checkbox', 'default' => $this->_are_settings_empty( $this->prefs_name) ? false : 1, ), 'ignore_output_group' => array( 'note' => $ignore_text, 'type' => 'checkbox', 'default' => $this->_are_settings_empty( $this->output_name) ? false : 1, ), /* AD Connection settings */ '_domain_controllers' => array( 'note' => __( 'Separate with semicolons, e.g. "dc1.domain.tld;dc2.domain.tld".', $this->text_domain ), 'default' => null, ), '_base_dn' => array( 'note' => __( 'e.g., "ou=unit,dc=domain,dc=tld"', $this->text_domain ), 'default' => null, ), '_use_ssl' => array( 'note' => __( 'Bind to the LDAP server using an secure socket layer (SSL) connection. When using SSL, a port of 636 will always be used, no matter what is specified in the "port" setting below.', $this->text_domain ), 'type' => 'checkbox', 'default' => true, ), '_use_tls' => array( 'note' => __( 'Secure the connection between the WordPress and the Active Directory Servers using TLS after the bind occurs.', $this->text_domain ), 'type' => 'checkbox', 'default' => true, ), '_ad_port' => array( 'note' => __( 'Defaults to 389', $this->text_domain ), 'class' => 'num', 'default' => 389 ), '_ad_username' => array( 'note' => __( 'Username for non-anonymous requests to AD (e.g. "ldapuser@domain.tld"). Leave empty for anonymous requests.', $this->text_domain ), 'default' => null, ), '_ad_password' => array( 'type' => 'password', 'default' => null, ), '_account_suffix' => array( 'note' => __( 'If an account suffix (e.g. "@mydomain.local") needs to be appended to the bind user before it can be authenticated, enter that suffix here.', $this->text_domain ), 'default' => null, ), 'always_ignore' => array( 'default' => '', 'note' => __( 'Must be entered in a format that can be directly fed into the LDAP query. If you are not familiar with LDAP queries, please do not use this field. This additional information will be applied to every LDAP query made.', $this->text_domain ), 'type' => 'textarea', 'class' => 'large-text', ), /* List Preferences */ 'ad_group' => $this->get_ad_group_field_details(), '_available_fields' => array( 'default' => null, 'type' => 'textarea', 'value' => str_replace( ': ', '=>', implode( "\n", $template_tags ) ), 'class' => 'large-text', 'note' => __( 'Please enter one field per line. You should enter each field in the following pattern: field_name=>brief description of field.
You will need to save the options before the list below will be updated.
', $this->text_domain ), ), 'fields_to_show' => array( 'default' => array( 'displayname', 'givenname', 'cn', 'mail', 'telephonenumber', 'department' ), 'type' => 'select', 'options' => $template_tags, 'multiple' => true, 'class' => 'widefat', ), 'results_per_page' => array( 'default' => 25, 'class' => 'narrow', 'note' => 'Leaving this field blank will cause the plugin to attempt to display all retrieved results in one list. Otherwise, the results will be paginated with this many results showing on each page.', ), 'order_by' => array( 'type' => 'select', 'options' => $template_tags, 'class' => 'widefat', 'note' => 'If this option is not set, the list will be returned in the order it is retrieved from the AD server.', ), /* Output options */ 'before_list' => array( 'default' => '', 'note' => __( 'Any HTML code you would like to appear before the list of employees. This code is output before the opening title_wrap tag.', $this->text_domain ), 'type' => 'textarea', 'class' => 'large-text', ), 'after_list' => array( 'default' => '', 'note' => __( 'Any HTML code you would like to appear after the list of employees. This code is output after the closing list_wrap tag.', $this->text_domain ), 'type' => 'textarea', 'class' => 'large-text', ), 'after_title' => array( 'default' => '', 'note' => __( 'Any HTML code you would like to appear between the closing title_wrap tag and the opening list_wrap tag.', $this->text_domain ), 'type' => 'textarea', 'class' => 'large-text', ), 'title_wrap' => array( 'default' => 'h2', 'note' => __( 'The HTML element you would like to use to wrap the list title (if set). Just the element name, please; no opening or closing brackets.', $this->text_domain ), ), 'title_class' => array( 'default' => 'adel-title', 'note' => __( 'The CSS class you would like applied to the list title (if set). If you would prefer that no CSS class be applied to the title, leave this blank.', $this->text_domain ), ), 'title_id' => array( 'default' => '', 'note' => __( 'If you would like to apply an HTML ID to the list title, you can indicate that here. Remember that IDs should be unique, so, if you plan on using multiple employee lists on a single page, you should leave this blank.', $this->text_domain ), ), 'title' => array( 'default' => __( 'List of Employees', $this->text_domain ), 'note' => __( 'The title you would like to appear at the top of the list. The title is output prior to the opening of the list itself.', $this->text_domain ), ), 'list_wrap' => array( 'default' => 'ul', 'note' => __( 'The HTML element you would like to use to wrap the entire list. Just the element name, please; no opening or closing brackets.', $this->text_domain ), ), 'list_class' => array( 'default' => 'adel-list', 'note' => __( 'The CSS class you would like to assign to the opening list_wrap tag, aiding in styling the entire list. If you would prefer that no CSS class be applied to the list, leave this blank.', $this->text_domain ), ), 'list_id' => array( 'default' => '', 'note' => __( 'If you would like to apply an HTML ID to the list itself, you can indicate that here. Remember that IDs should be unique, so, if you plan on using multiple employee lists on a single page, you should leave this blank.', $this->text_domain ), ), 'item_wrap' => array( 'default' => 'li', 'note' => __( 'The HTML element you would like to use to wrap each individual employee in the list. Just the element name, please; no opening or closing brackets.', $this->text_domain ), ), 'item_class' => array( 'default' => 'adel-list-item', 'note' => __( 'The CSS class you would like to assign to each individual employee in the list. If you would prefer that no CSS class be applied to the list, leave this blank.', $this->text_domain ), ), 'item_id' => array( 'default' => 'adel-list-item-%samaccountname%', 'note' => __( 'If you would like to apply an HTML ID to each individual employee in the list, you can indicate that here. You can use placeholder variables for user information (any of the fields that are set to be retrieved, plus the user\'s username (samaccountname). Simply wrap the placeholder variable with percent symbols (so, to use a placeholder for samaccountname, use %samaccountname%) All disallowed characters (the @ symbol, dots, spaces, etc.) will be replaced with hyphens. Remember that IDs should be unique, so, if you plan on using multiple employee lists that may include the same employee multiple times on a single page, you should leave this blank. Likewise, you should use a placeholder variable that will be unique.', $this->text_domain ), ), 'prev_page_link' => array( 'default' => 'Previous page', 'note' => 'Please provide the HTML code you would like to use as the link to previous pages of results. You should use the %link% keyword where you would like the URL to appear. If this field is left blank, the link will not appear on the page at all.', ), 'next_page_link' => array( 'default' => '', 'note' => 'Please provide the HTML code you would like to use as the link to the next pages of results. You should use the %link% keyword where you would like the URL to appear. If this field is left blank, the link will not appear on the page at all.', ), 'output_builder' => array( 'default' => '<article id="adel-employee-%samaccountname%"> <p> [if mail] <a href="mailto:%mail%">%displayname%</a> [else] %displayname% [endif] <br/> %telephonenumber% <br/> %department% </p> </article>', 'note' => __( 'Please indicate how you would like the information for each individual employee to be output within its list item wrapper. If this is left blank, the employee\'s information will simply be wrapped in a<ul> element with each field retrieved from the database being wrapped in <li> elements.', $this->text_domain ),
'type' => 'textarea',
'class' => 'large-text',
'hidenote' => $this->get_output_builder_instructions(),
),
);
}
return $this->_settings_fields[$field];
}
/**
* Retrieve specific information about the ad_group field
*/
function get_ad_group_field_details() {
$rt = array(
'default' => false,
);
$g = $this->get_all_groups();
if( !empty( $g ) ) {
$rt['type'] = 'select';
$rt['multiple'] = true;
$rt['options'] = $g;
$rt['note'] = __( 'Only users that belong to the groups selected in this field will be retrieved when the list of users is pulled from Active Directory. To select multiple groups, please use the Ctrl or Cmd button on your keyboard when clicking on the individual groups.', $this->text_domain );
} else {
$rt['type'] = 'text';
$rt['note'] = __( 'Only users that belong to the groups listed in this field will be retrieved when the list of users is pulled from Active Directory. Please use the CN portion of the group name. To indicate multiple groups, please separate them with a semi-colon.', $this->text_domain );
}
return $rt;
}
/**
* Output the description of the settings section
*/
function settings_section( $wrap='p' ) {
if( empty( $wrap ) )
$wrap = 'p';
printf( __( '<%1$s>This is the section where options are set for connecting to the active directory server.%1$s>', $this->text_domain ), $wrap );
}
/**
* Output the description for the preferences section
*/
function prefs_section( $wrap='p' ) {
if( empty( $wrap ) )
$wrap = 'p';
printf( __( '<%1$s>This is the section where you set options as to what gets displayed in the employee list.%1$s>', $this->text_domain ), $wrap );
}
/**
* Output the description for the output section
*/
function output_section( $wrap='p' ) {
if( empty( $wrap ) )
$wrap = 'p';
printf( __( '<%1$s>This is the section where you set any preferences/options for the way the employee list is output on the page/post.%1$s>', $this->text_domain ), $wrap );
}
/**
* Output the appropriate error message about the user not having the right permissions
*/
protected function _no_permissions() {
?>
text_domain ) ?>
The %s options were %supdated%s.
' ), $this->settings_titles[$k], ( true === $v ? '' : 'not ' ), ( true === $v ? ' successfully' : '' ) ); } ?>Any options you set and save on this screen will override the global multi-network options that were set on the multi-network options page.
To avoid overriding a specific set of options, please check the "%s" box in the appropriate settings section.
', $this->text_domain ), $url, __( 'Ignore this group of options?', $this->text_domain ) ); } elseif( !is_network_admin() && is_multisite() && is_plugin_active_for_network( 'active-directory-employee-list/active-directory-employee-list.php' ) ) { $url = network_admin_url( 'settings.php?page=' . $this->settings_page ); printf( __( 'Any options you set and save on this screen will override the network options that were set on the network options page.
To avoid overriding a specific set of options, please check the "%s" box in the appropriate settings section.
', $this->text_domain ), $url, __( 'Ignore this group of options?', $this->text_domain ) ); } ?>