- /* 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 html_tag( 'table',
- html_tag( 'tr',
- html_tag( 'td',
- '<INPUT TYPE=submit NAME=editaddr VALUE="' .
- _("Edit selected") . "\">\n" .
- '<INPUT TYPE=submit NAME=deladdr VALUE="' .
- _("Delete selected") . "\">\n",
- 'center', '', 'colspan="5"' )
- ) .
- html_tag( 'tr',
- html_tag( 'td', ' <br>', 'center', '', 'colspan="5"' )
- ) ,
- 'center' );
- }
-
- echo html_tag( 'table',
- html_tag( 'tr',
- html_tag( 'td', "\n" . '<strong>' . $row['source'] . '</strong>' . "\n", 'center', $color[0] )
- ) ,
- 'center', '', 'width="95%" cols="1"' ) ."\n"
- . html_tag( 'table', '', 'center', '', 'cols="5" border="0" cellpadding="1" cellspacing="0" width="90%"' ) .
- html_tag( 'tr', "\n" .
- html_tag( 'th', ' ', 'left', '', 'width="1%"' ) .
- html_tag( 'th', _("Nickname"), 'left', '', 'width="1%"' ) .
- html_tag( 'th', _("Name"), 'left', '', 'width="1%"' ) .
- html_tag( 'th', _("E-mail"), 'left', '', 'width="1%"' ) .
- html_tag( 'th', _("Info"), 'left', '', 'width="1%"' ) ,
- '', $color[9] ) . "\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 */
- $tr_bgcolor = '';
- if ($line % 2) { $tr_bgcolor = $color[0]; }
- echo html_tag( 'tr', '') .
- html_tag( 'td',
- '<SMALL>' .
- '<INPUT TYPE=checkbox ' . $selected . ' NAME="sel[]" VALUE="' .
- $row['backend'] . ':' . $row['nickname'] . '"></SMALL>' ,
- 'center', '', 'valign="top" width="1%"' ) .
- html_tag( 'td', ' ' . $row['nickname'] . ' ', 'left', '', 'valign="top" width="1%" nowrap' ) .
- html_tag( 'td', ' ' . $row['name'] . ' ', 'left', '', 'valign="top" width="1%" nowrap' ) .
- html_tag( 'td', '', 'left', '', 'valign="top" width="1%" nowrap' ) . ' ';
- $email = $abook->full_address($row);
- if ($compose_new_win == '1') {
- echo '<a href="javascript:void(0)" onclick=comp_in_new(false,"compose.php?send_to='.rawurlencode($email).'")>';
- }
- else {
- echo '<A HREF="compose.php?send_to=' . rawurlencode($email).'">';
- }
- echo htmlspecialchars($row['email']) . '</A> </td>'."\n".
- html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'valign="top" width="1%"' ) .
- "</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;