+ $addresses[$backend->bnum] = $a;
+ }
+}
+
+
+$current_page_args = array(
+ 'abook_sort_order' => $abook_sort_order,
+ 'new_bnum' => $current_backend,
+ 'page_number' => $page_number,
+ );
+
+
+// note that plugins can add to $current_page_args as well as
+// filter the address list
+//
+$temp = array(&$addresses, &$current_backend, &$page_number, &$current_page_args);
+do_hook('abook_list_filter', $temp);
+
+
+// NOTE to address book backend authors and plugin authors: if a backend does
+// pagination (which might be more efficient), it needs to place a key
+// in every address listing it returns called "paginated", whose value
+// should evaluate to boolean TRUE. However, if a plugin will also be
+// used on the hook above to filter the addresses (perhaps by group), then
+// the backend should be made compatible with the filtering plugin and
+// should do the actual filtering too. Otherwise, the backend will paginate
+// before filtering has taken place, the output of which is clearly wrong.
+// It is proposed that filtering be based on a GET/POST variable called
+// "abook_groups_X" where X is the current backend number. The value of
+// this varaible would be an array of possible filter names, which the
+// plugin and the backend would both know about. The plugin would only
+// filter based on that value if the backend didn't already do it. The
+// backend can insert a "grouped" key into all address listings, whose
+// value evaluates to boolean TRUE, telling the plugin not to do any
+// filtering itself. For an example of this implementation, see the
+// Address Book Grouping and Pagination plugin.
+
+
+// if no pagination was done by a plugin or the abook
+// backend (which is indicated by the presence of a
+// "paginated" key within all of the address entries
+// in the list of addresses for the backend currently
+// being viewed), then we provide default pagination
+//
+$total_addresses = 0;
+if (!$show_all
+ && is_array($addresses[$current_backend]['Addresses'])
+ && empty($addresses[$current_backend]['Addresses'][0]['paginated'])) {
+
+ // at this point, we assume the current list is
+ // the *full* list
+ //
+ $total_addresses = sizeof($addresses[$current_backend]['Addresses']);
+
+ // iterate through all the entries, building list of addresses
+ // to keep based on current page
+ //
+ $new_address_list = array();
+ $total_pages = ceil($total_addresses / $page_size);
+ if ($page_number > $total_pages) $page_number = $total_pages;
+ $page_count = 1;
+ $page_item_count = 0;
+ foreach ($addresses[$current_backend]['Addresses'] as $addr) {
+ $page_item_count++;
+ if ($page_item_count > $page_size) {
+ $page_count++;
+ $page_item_count = 1;
+ }
+ if ($page_count == $page_number)
+ $new_address_list[] = $addr;