- /* List addresses */
- if (count($alist) > 0) {
- echo '<FORM ACTION="' . $PHP_SELF . '" METHOD="POST">' . "\n";
- while(list($undef,$row) = each($alist)) {
-
- /* New table header for each backend */
- if($prevbackend != $row['backend']) {
- if($prevbackend >= 0) {
- echo '<TR><TD COLSPAN=5 ALIGN=center>' . "\n" .
- '<INPUT TYPE=submit NAME=editaddr VALUE="' .
- _("Edit selected") . "\">\n" .
- '<INPUT TYPE=submit NAME=deladdr VALUE="' .
- _("Delete selected") . "\">\n</tr>\n" .
- '<TR><TD COLSPAN="5" ALIGN=center>' .
- ' <BR></TD></TR></TABLE>' . "\n";
- }
-
- echo '<TABLE WIDTH="95%" COLS=1 ALIGN=CENTER>' . "\n" .
- '<TR><TD BGCOLOR="' . $color[0] . '" ALIGN=CENTER>' . "\n" .
- '<STRONG>' . $row['source'] .
- "</STRONG>\n</TD></TR>\n</TABLE>\n" .
- '<TABLE COLS="5" BORDER="0" CELLPADDING="1" CELLSPACING="0"' .
- ' WIDTH="90%" ALIGN="center">' .
- '<TR BGCOLOR="' . $color[9] .
- '"><TH ALIGN=left WIDTH="1%"> <TH ALIGN=left WIDTH="1%">' .
- _("Nickname") . '<TH ALIGN=left WIDTH="1%">' . _("Name") .
- '<TH ALIGN=left WIDTH="1%">' . _("E-mail") .
- '<TH ALIGN=left WIDTH="%">' . _("Info") . "</TR>\n";
-
- $line = 0;
- $headerprinted = true;
- } /* End of header */
-
- $prevbackend = $row['backend'];
-
- /* Check if this user is selected */
- if(in_array($row['backend'] . ':' . $row['nickname'], $defselected)) {
- $selected = 'CHECKED';
- } else {
- $selected = '';
- }
-
- /* Print one row */
- echo '<TR';
- if ($line % 2) { echo ' bgcolor="' . $color[0]. '"'; }
- echo '><TD VALIGN=top ALIGN=center WIDTH="1%"><SMALL>' .
- '<INPUT TYPE=checkbox ' . $selected . ' NAME="sel[]" VALUE="' .
- $row['backend'] . ':' . $row['nickname'] . '"></SMALL></TD>' .
- '<TD VALIGN=top NOWRAP WIDTH="1%"> ' . $row['nickname'] .
- ' </TD>' .
- '<TD VALIGN=top NOWRAP WIDTH="1%"> ' . $row['name'] .
- ' </TD>',
- '<TD VALIGN=top NOWRAP WIDTH="1%"> ' .
- '<A HREF="compose.php?send_to=' . rawurlencode($row['email']) .
- '">' . $row['email'] . '</A> </TD>'."\n",
- '<TD VALIGN=top WIDTH="1%"> ' . $row['label'] . ' </TD>' .
- "</TR>\n";
- $line++;
+$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;