| | 23 | <?php |
|---|
| | 24 | //Added functions to speed up Page Management page load |
|---|
| | 25 | function &lp_get_pages($_pages) { |
|---|
| | 26 | |
|---|
| | 27 | // permalink stuff |
|---|
| | 28 | global $wp_rewrite; |
|---|
| | 29 | $pagestruct = $wp_rewrite->get_page_permastruct(); |
|---|
| | 30 | $home = get_settings('home'); |
|---|
| | 31 | |
|---|
| | 32 | $pages = array(); |
|---|
| | 33 | $deferred = array(); |
|---|
| | 34 | |
|---|
| | 35 | foreach ($_pages as $k=>$page) { |
|---|
| | 36 | |
|---|
| | 37 | $id = $page['id']; |
|---|
| | 38 | $parent = $page['post_parent']; |
|---|
| | 39 | |
|---|
| | 40 | $_pages[$k]['root_page'] = empty($parent); |
|---|
| | 41 | $_pages[$k]['children'] = array(); |
|---|
| | 42 | |
|---|
| | 43 | if (!empty($parent) && $parent != $id) { |
|---|
| | 44 | if (isset($pages[$parent])) |
|---|
| | 45 | $pages[$parent]['children'][$page['menu_order'] . $page['post_title']] =& $_pages[$k]; |
|---|
| | 46 | else |
|---|
| | 47 | $deferred[$id] = array($page['menu_order'] . $page['post_title'], $parent); |
|---|
| | 48 | } |
|---|
| | 49 | $pages[$id] =& $_pages[$k]; |
|---|
| | 50 | |
|---|
| | 51 | } |
|---|
| | 52 | |
|---|
| | 53 | foreach ($deferred as $id=>$details) { |
|---|
| | 54 | list($title, $parent) = $details; |
|---|
| | 55 | if (isset($pages[$parent])) |
|---|
| | 56 | $pages[$parent]['children'][$title] =& $pages[$id]; |
|---|
| | 57 | else |
|---|
| | 58 | $pages[$id]['parent'] = ''; |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | /* |
|---|
| | 62 | Add unpublished pages to the begining of the page list |
|---|
| | 63 | */ |
|---|
| | 64 | $temp_pages_list = $pages; |
|---|
| | 65 | $unpublished_pages = array(); |
|---|
| | 66 | $array_offset = 0; |
|---|
| | 67 | foreach ($temp_pages_list as $id => $page) |
|---|
| | 68 | { |
|---|
| | 69 | if ($page['post_date'] == '0000-00-00 00:00:00') |
|---|
| | 70 | { |
|---|
| | 71 | $slice = array_splice($pages, $array_offset, 1); |
|---|
| | 72 | $unpublished_pages[] = $slice[0]; |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| | 75 | $array_offset++; |
|---|
| | 76 | } |
|---|
| | 77 | $unpublished_pages = array_reverse($unpublished_pages); |
|---|
| | 78 | foreach ($unpublished_pages as $unpublished_page) |
|---|
| | 79 | array_unshift($pages, $unpublished_page); |
|---|
| | 80 | |
|---|
| | 81 | |
|---|
| | 82 | foreach ($pages as $id=>$page) { |
|---|
| | 83 | |
|---|
| | 84 | $parent = $page['post_parent']; |
|---|
| | 85 | |
|---|
| | 86 | if (empty($pagestruct)) { |
|---|
| | 87 | $link = "$home/?page_id=$id"; |
|---|
| | 88 | } else { |
|---|
| | 89 | $uri = urldecode($page['post_name']); |
|---|
| | 90 | if ($parent != $id) { |
|---|
| | 91 | while (!empty($parent) && isset($pages[$parent])) { |
|---|
| | 92 | $uri = urldecode($pages[$parent]['post_name']) . "/$uri"; |
|---|
| | 93 | $parent = $pages[$parent]['post_parent']; |
|---|
| | 94 | } |
|---|
| | 95 | } |
|---|
| | 96 | $link = $home . '/' . str_replace('%pagename%', $uri, $pagestruct) . '/'; |
|---|
| | 97 | } |
|---|
| | 98 | $pages[$id]['permalink'] = apply_filters('page_link', $link, $id); |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | return $pages; |
|---|
| | 102 | } |
|---|
| | 103 | |
|---|
| | 104 | function recurse(&$tree, $padding='', $index=0) { |
|---|
| | 105 | |
|---|
| | 106 | foreach ($tree as $post) { |
|---|
| | 107 | if (empty($padding) && !empty($post['post_parent'])) |
|---|
| | 108 | continue; |
|---|
| | 109 | $index++; |
|---|
| | 110 | $title = wp_specialchars($post['post_title']); |
|---|
| | 111 | $id = $post['id']; |
|---|
| | 112 | $class = (($index%2)==1) ? '' : 'alternate'; |
|---|
| | 113 | |
|---|
| | 114 | ?> |
|---|
| | 115 | <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'> |
|---|
| | 116 | <th scope="row" style="text-align: center"><?php echo $id; ?></th> |
|---|
| | 117 | <td> |
|---|
| | 118 | <?php echo $padding; ?><?php echo $title; ?> |
|---|
| | 119 | </td> |
|---|
| | 120 | <td><?php echo $post['display_name']; ?></td> |
|---|
| | 121 | <td><?php if ( '0000-00-00 00:00:00' ==$post['post_date'] ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post['post_modified'] ); ?></td> |
|---|
| | 122 | <td><a href="<?php if ('0000-00-00 00:00:00' ==$post['post_date']) echo "/?page_id=$id"; else echo $post['permalink']; ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td> |
|---|
| | 123 | <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td> |
|---|
| | 124 | <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&post=$id", 'delete-page_' . $id ) . "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), $title ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td> |
|---|
| | 125 | </tr> |
|---|
| | 126 | <?php |
|---|
| | 127 | |
|---|
| | 128 | ksort($post['children']); |
|---|
| | 129 | $index = recurse($post['children'], $padding . '— ', $index); |
|---|
| | 130 | } |
|---|
| | 131 | return $index; |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | ?> |
|---|
| | 135 | |
|---|