| 1507 | |
| 1508 | /** Group extensions management specific functions ****/ |
| 1509 | |
| 1510 | /** |
| 1511 | * Prints some style in Group Management page header |
| 1512 | * |
| 1513 | * @return string css styles |
| 1514 | */ |
| 1515 | function bp_groups_extensions_admin_cssjs() { |
| 1516 | ?> |
| 1517 | <style> |
| 1518 | table.widefat span.deactivate a.delete{ |
| 1519 | color:#bc0b0b; |
| 1520 | } |
| 1521 | .extensions tr { |
| 1522 | background-color: #fcfcfc; |
| 1523 | } |
| 1524 | .extensions .inactive { |
| 1525 | background-color: #f4f4f4; |
| 1526 | } |
| 1527 | </style> |
| 1528 | <?php |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Group Extensions management process |
| 1533 | * |
| 1534 | * Setting default options for group extensions, these settings can be overidden by each group |
| 1535 | * from group admin ui |
| 1536 | * |
| 1537 | * @global WP_List_Table $bp_groups_extensions_list_table |
| 1538 | * @global string $status status of the extensions (all, inactive, active) |
| 1539 | * @global integer $page the current number of page |
| 1540 | * @uses BP_Groups_Extensions_List_Table to build the html table of available extensions |
| 1541 | * @uses get_current_screen() to get current admin screen attributes |
| 1542 | * @uses add_action() to load some style in page header |
| 1543 | * @uses bp_get_admin_url() to build the url of this current page |
| 1544 | * @uses remove_query_arg() to strip some args from the requested url |
| 1545 | * @uses current_user_can() to check for current user's capability |
| 1546 | * @uses wp_die() to eventually kill the process if user has not enought capability |
| 1547 | * @uses check_admin_referer() for security reasons |
| 1548 | * @uses bp_groups_extensions_set_inactive() to set a group extension as inactive |
| 1549 | * @uses bp_groups_extensions_set_active() to set a group extension as active |
| 1550 | * @uses wp_redirect() to safely redirect user after settings are saved |
| 1551 | * @return string html output |
| 1552 | */ |
| 1553 | function bp_groups_admin_extensions_load() { |
| 1554 | global $bp_groups_extensions_list_table, $status, $page; |
| 1555 | |
| 1556 | $bp_groups_extensions_list_table = new BP_Groups_Extensions_List_Table(); |
| 1557 | |
| 1558 | // Help panel - overview text |
| 1559 | get_current_screen()->add_help_tab( array( |
| 1560 | 'id' => 'bp-groups-extensions-overview', |
| 1561 | 'title' => __( 'Overview', 'buddypress' ), |
| 1562 | 'content' => |
| 1563 | '<p>' . __( 'You can manage group extensions much like you can manage plugins. You can act on available default group extensions by using the on-hover action links or the Bulk Actions.', 'buddypress' ) . '</p>', |
| 1564 | ) ); |
| 1565 | |
| 1566 | get_current_screen()->add_help_tab( array( |
| 1567 | 'id' => 'bp-groups-overview-actions', |
| 1568 | 'title' => __( 'Group Extensions Actions', 'buddypress' ), |
| 1569 | 'content' => |
| 1570 | '<p>' . __( 'Clicking "Deactivate" will disable the group extension. Newly created group will not be able to use the extension. In the Group Admin, you can still activate the extension for the group being edited', 'buddypress' ) . '</p>' . |
| 1571 | '<p>' . __( 'Clicking "Activate" will bring back a group extension previously deactivated. In the Group Admin, you can still deactivate the extension for the group being edited.', 'buddypress' ) . '</p>' . |
| 1572 | '<p>' . __( 'If you select a number of extensions and then choose Deactivate or Activate from the Bulk Actions menu, you will be able to change the selected extensions status at once', 'buddypress' ) . '</p>', |
| 1573 | ) ); |
| 1574 | |
| 1575 | // Help panel - sidebar links |
| 1576 | get_current_screen()->set_help_sidebar( |
| 1577 | '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . |
| 1578 | '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' |
| 1579 | ); |
| 1580 | |
| 1581 | add_action( 'admin_print_styles-' . get_current_screen()->id, 'bp_groups_extensions_admin_cssjs' ); |
| 1582 | |
| 1583 | $pagenum = $bp_groups_extensions_list_table->get_pagenum(); |
| 1584 | |
| 1585 | $action = $bp_groups_extensions_list_table->current_action(); |
| 1586 | |
| 1587 | // Build redirection URL |
| 1588 | $redirect_to = bp_get_admin_url( 'admin.php?page=bp-groups-extensions' ); |
| 1589 | |
| 1590 | $extension = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : ''; |
| 1591 | $s = isset($_REQUEST['s']) ? urlencode($_REQUEST['s']) : ''; |
| 1592 | |
| 1593 | // Clean up request URI from temporary args for screen options/paging uri's to work as expected. |
| 1594 | $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'error', 'activate', 'deactivate', 'activate-multi', 'deactivate-multi', '_error_nonce' ), $_SERVER['REQUEST_URI'] ); |
| 1595 | |
| 1596 | // redirect ! |
| 1597 | if( ! empty( $action ) ) { |
| 1598 | |
| 1599 | switch( $action ) { |
| 1600 | |
| 1601 | case 'deactivate' : |
| 1602 | if ( ! current_user_can('bp_moderate') ) |
| 1603 | wp_die( __('You do not have sufficient permissions to deactivate group extensions for this site.', 'buddypress') ); |
| 1604 | |
| 1605 | check_admin_referer( 'bp-groups-extensions-deactivate' ); |
| 1606 | |
| 1607 | $deactivated = bp_groups_extensions_set_inactive( $extension ); |
| 1608 | |
| 1609 | wp_redirect( "$redirect_to&deactivate=$deactivated&extension_status=$status&paged=$page&s=$s" ); |
| 1610 | exit; |
| 1611 | |
| 1612 | break; |
| 1613 | |
| 1614 | case 'activate' : |
| 1615 | if ( ! current_user_can('bp_moderate') ) |
| 1616 | wp_die( __('You do not have sufficient permissions to activate group extensions for this site.', 'buddypress') ); |
| 1617 | |
| 1618 | check_admin_referer( 'bp-groups-extensions-activate' ); |
| 1619 | |
| 1620 | $activated = bp_groups_extensions_set_active( $extension ); |
| 1621 | |
| 1622 | wp_redirect( "$redirect_to&activate=$activated&extension_status=$status&paged=$page&s=$s" ); |
| 1623 | exit; |
| 1624 | |
| 1625 | break; |
| 1626 | |
| 1627 | case 'deactivate-selected' : |
| 1628 | if ( ! current_user_can('bp_moderate') ) |
| 1629 | wp_die( __('You do not have sufficient permissions to deactivate group extensions for this site.', 'buddypress') ); |
| 1630 | |
| 1631 | check_admin_referer( 'bulk-extensions' ); |
| 1632 | |
| 1633 | $extensions = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); |
| 1634 | |
| 1635 | if ( empty( $extensions ) ) { |
| 1636 | wp_redirect( "$redirect_to&extension_status=$status&paged=$page&s=$s" ); |
| 1637 | exit; |
| 1638 | } |
| 1639 | |
| 1640 | $deactivated = bp_groups_extensions_set_inactive( $extensions ); |
| 1641 | |
| 1642 | wp_redirect( "$redirect_to&deactivate-multi=$deactivated&extension_status=$status&paged=$page&s=$s" ); |
| 1643 | exit; |
| 1644 | |
| 1645 | break; |
| 1646 | |
| 1647 | case 'activate-selected' : |
| 1648 | if ( ! current_user_can('bp_moderate') ) |
| 1649 | wp_die( __('You do not have sufficient permissions to deactivate group extensions for this site.', 'buddypress') ); |
| 1650 | |
| 1651 | check_admin_referer( 'bulk-extensions' ); |
| 1652 | |
| 1653 | $extensions = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); |
| 1654 | |
| 1655 | if ( empty( $extensions ) ) { |
| 1656 | wp_redirect( "$redirect_to&extension_status=$status&paged=$page&s=$s" ); |
| 1657 | exit; |
| 1658 | } |
| 1659 | |
| 1660 | $activated = bp_groups_extensions_set_active( $extensions ); |
| 1661 | |
| 1662 | wp_redirect( "$redirect_to&activate-multi=$activated&extension_status=$status&paged=$page&s=$s" ); |
| 1663 | exit; |
| 1664 | |
| 1665 | break; |
| 1666 | |
| 1667 | } |
| 1668 | |
| 1669 | } |
| 1670 | |
| 1671 | } |
| 1672 | |
| 1673 | /** |
| 1674 | * Merges the extension's plugin info |
| 1675 | * |
| 1676 | * @param array $extensions_dir the calculated extensions plugin directories |
| 1677 | * @uses get_plugins() to get the installed plugins |
| 1678 | * @return array plugin's info |
| 1679 | */ |
| 1680 | function bp_groups_admin_extensions_get_parent_plugin_infos( $extensions_dir = array() ) { |
| 1681 | $all_plugins = get_plugins(); |
| 1682 | $parent_plugin_infos = array(); |
| 1683 | |
| 1684 | $plugin_keys = array_keys( $all_plugins ); |
| 1685 | |
| 1686 | foreach( $extensions_dir as $key => $extension ) { |
| 1687 | foreach( $plugin_keys as $plugin_key ) { |
| 1688 | if( strpos( $plugin_key, $extension ) !== false ) { |
| 1689 | $parent_plugin_infos[$key]['parent_plugin'] = $plugin_key; |
| 1690 | $parent_plugin_infos[$key]['parent_plugin_data'] = $all_plugins[$plugin_key]; |
| 1691 | } |
| 1692 | |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | return $parent_plugin_infos; |
| 1697 | } |
| 1698 | |
| 1699 | /** |
| 1700 | * Builds the list of available group extensions |
| 1701 | * |
| 1702 | * @uses bp_groups_extension_get_plugin_basename() to get parent plugin's folder |
| 1703 | * @uses bp_groups_admin_extensions_get_parent_plugin_infos() to merge plugin's infos |
| 1704 | * @return array the list of group extensions |
| 1705 | */ |
| 1706 | function bp_groups_admin_extensions_build_list() { |
| 1707 | global $wp_filter; |
| 1708 | |
| 1709 | $extensions = array(); |
| 1710 | $all_plugins = get_plugins(); |
| 1711 | |
| 1712 | foreach ( buddypress()->groups->extensions as $extension_slug => $extension ) { |
| 1713 | $extensions[ $extension->slug ] = array( |
| 1714 | 'settings' => array( |
| 1715 | 'create' => $extension->screens['create']['enabled'], |
| 1716 | 'edit' => $extension->screens['edit']['enabled'], |
| 1717 | 'admin' => $extension->screens['admin']['enabled'], |
| 1718 | ), |
| 1719 | 'class_name' => $extension->class_name, |
| 1720 | ); |
| 1721 | |
| 1722 | // Find the parent plugin info |
| 1723 | foreach ( $all_plugins as $plugin_key => $plugin ) { |
| 1724 | if ( 0 === strpos( $plugin_key, $extension->plugin_basename . '/' ) ) { |
| 1725 | $extensions[ $extension->slug ]['parent_plugin'] = $plugin_key; |
| 1726 | $extensions[ $extension->slug ]['parent_plugin_data'] = $plugin; |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | return $extensions; |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * Main page to manage the Group Extensions |
| 1736 | * |
| 1737 | * @global WP_List_Table $bp_groups_extensions_list_table |
| 1738 | * @global string $status (active, inactive or all) |
| 1739 | * @global integer $page the current page number |
| 1740 | * @uses screen_icon() to output groups logo |
| 1741 | * @return string html output |
| 1742 | */ |
| 1743 | function bp_groups_admin_extensions() { |
| 1744 | global $bp_groups_extensions_list_table, $status, $page; |
| 1745 | |
| 1746 | $bp_groups_extensions_list_table->prepare_items(); |
| 1747 | |
| 1748 | if ( isset($_GET['activate']) ) : ?> |
| 1749 | <div id="message" class="updated"><p><?php _e( 'Group extension <strong>activated</strong>.', 'buddypress' ) ?></p></div> |
| 1750 | <?php elseif (isset($_GET['activate-multi'])) : ?> |
| 1751 | <div id="message" class="updated"><p><?php _e( 'Selected Group extensions <strong>activated</strong>.', 'buddypress' ); ?></p></div> |
| 1752 | <?php elseif ( isset($_GET['deactivate']) ) : ?> |
| 1753 | <div id="message" class="updated"><p><?php _e( 'Group extension <strong>deactivated</strong>.', 'buddypress' ) ?></p></div> |
| 1754 | <?php elseif (isset($_GET['deactivate-multi'])) : ?> |
| 1755 | <div id="message" class="updated"><p><?php _e( 'Selected Group extensions <strong>deactivated</strong>.', 'buddypress' ); ?></p></div> |
| 1756 | <?php endif; ?> |
| 1757 | |
| 1758 | <div class="wrap"> |
| 1759 | <?php screen_icon( 'buddypress-groups' ); ?> |
| 1760 | <h2><?php _e( 'Group Extensions Management', 'buddypress' ) ?></h2> |
| 1761 | |
| 1762 | <?php $bp_groups_extensions_list_table->views(); ?> |
| 1763 | |
| 1764 | <form method="get" action=""> |
| 1765 | <?php $bp_groups_extensions_list_table->search_box( __( 'Search Group extensions' ), 'extension' ); ?> |
| 1766 | </form> |
| 1767 | |
| 1768 | <form method="post" action=""> |
| 1769 | |
| 1770 | <input type="hidden" name="plugin_status" value="<?php echo esc_attr($status) ?>" /> |
| 1771 | <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" /> |
| 1772 | |
| 1773 | <?php $bp_groups_extensions_list_table->display(); ?> |
| 1774 | </form> |
| 1775 | |
| 1776 | </div> |
| 1777 | <?php |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * Sets a group extension as active |
| 1782 | * |
| 1783 | * @param string $class the name of the group extension class |
| 1784 | * @uses bp_get_option() to get previously saved setting |
| 1785 | * @uses bp_update_option() to save the new settings |
| 1786 | * @uses bp_delete_option() to eventually delete the settings |
| 1787 | * @return boolean true|false |
| 1788 | */ |
| 1789 | function bp_groups_extensions_set_active( $class = '' ) { |
| 1790 | if( empty( $class ) ) |
| 1791 | return false; |
| 1792 | |
| 1793 | $inactive_extensions = bp_get_option( 'bp_inactive_group_extensions', array() ); |
| 1794 | |
| 1795 | // forcing array to use same function in case of bulk action |
| 1796 | foreach( (array) $class as $extension ) { |
| 1797 | if( in_array( $extension, $inactive_extensions ) ) |
| 1798 | $inactive_extensions = array_diff( $inactive_extensions, array( $extension ) ); |
| 1799 | } |
| 1800 | |
| 1801 | if( count( $inactive_extensions ) > 0 ) |
| 1802 | bp_update_option( 'bp_inactive_group_extensions', $inactive_extensions ); |
| 1803 | |
| 1804 | else |
| 1805 | bp_delete_option( 'bp_inactive_group_extensions' ); |
| 1806 | |
| 1807 | return true; |
| 1808 | } |
| 1809 | |
| 1810 | /** |
| 1811 | * Sets a group extension as inactive |
| 1812 | * |
| 1813 | * @param string $class the name of the group extension class |
| 1814 | * @uses bp_get_option() to get previously saved setting |
| 1815 | * @uses bp_update_option() to save the new settings |
| 1816 | * @uses sanitize_text_field() to sanitize class before inserting it in db |
| 1817 | * @return boolean true|false |
| 1818 | */ |
| 1819 | function bp_groups_extensions_set_inactive( $class = '' ) { |
| 1820 | if( empty( $class ) ) |
| 1821 | return false; |
| 1822 | |
| 1823 | $inactive_extensions = bp_get_option( 'bp_inactive_group_extensions', array() ); |
| 1824 | |
| 1825 | |
| 1826 | // forcing array to use same function in case of bulk action |
| 1827 | foreach( (array) $class as $extension ) { |
| 1828 | if( !in_array( $extension, $inactive_extensions ) ) |
| 1829 | $inactive_extensions[] = sanitize_text_field( $extension ); |
| 1830 | } |
| 1831 | |
| 1832 | if( count( $inactive_extensions ) > 0 ) |
| 1833 | bp_update_option( 'bp_inactive_group_extensions', $inactive_extensions ); |
| 1834 | |
| 1835 | return true; |
| 1836 | } |
| 1837 | |
| 1838 | /** |
| 1839 | * Group extensions list table |
| 1840 | */ |
| 1841 | class BP_Groups_Extensions_List_Table extends WP_List_Table { |
| 1842 | |
| 1843 | function __construct( $args = array() ) { |
| 1844 | global $status, $page; |
| 1845 | |
| 1846 | parent::__construct( array( |
| 1847 | 'ajax' => false, |
| 1848 | 'plural' => 'extensions', |
| 1849 | 'singular' => 'extension', |
| 1850 | ) ); |
| 1851 | |
| 1852 | $status = 'all'; |
| 1853 | if ( isset( $_REQUEST['extension_status'] ) && in_array( $_REQUEST['extension_status'], array( 'active', 'inactive', 'search' ) ) ) |
| 1854 | $status = $_REQUEST['extension_status']; |
| 1855 | |
| 1856 | if ( isset($_REQUEST['s']) ) |
| 1857 | $_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes_deep($_REQUEST['s']) ); |
| 1858 | |
| 1859 | $page = $this->get_pagenum(); |
| 1860 | } |
| 1861 | |
| 1862 | function get_table_classes() { |
| 1863 | return array( 'widefat', $this->_args['plural'] ); |
| 1864 | } |
| 1865 | |
| 1866 | function ajax_user_can() { |
| 1867 | return current_user_can('bp_moderate'); |
| 1868 | } |
| 1869 | |
| 1870 | function prepare_items() { |
| 1871 | global $status, $extensions, $totals, $page, $orderby, $order, $s; |
| 1872 | |
| 1873 | wp_reset_vars( array( 'orderby', 'order', 's' ) ); |
| 1874 | |
| 1875 | $extensions = array( |
| 1876 | 'all' => apply_filters( 'all_groups_extensions', bp_groups_admin_extensions_build_list() ), |
| 1877 | 'search' => array(), |
| 1878 | 'active' => array(), |
| 1879 | 'inactive' => array() |
| 1880 | ); |
| 1881 | |
| 1882 | $screen = $this->screen; |
| 1883 | |
| 1884 | $extensions['active'] = (array) $extensions['all']; |
| 1885 | |
| 1886 | foreach ( (array) $extensions['all'] as $extension_slug => $extension_data ) { |
| 1887 | if ( bp_groups_is_extension_active( $extension_slug ) ) { |
| 1888 | unset( $extensions['active'][$extension_slug] ); |
| 1889 | $extensions['inactive'][$extension_slug] = $extension_data; |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | if ( $s ) { |
| 1894 | $status = 'search'; |
| 1895 | $extensions['search'] = array_filter( $extensions['all'], array( &$this, '_search_callback' ) ); |
| 1896 | } |
| 1897 | |
| 1898 | $totals = array(); |
| 1899 | foreach ( $extensions as $type => $list ) |
| 1900 | $totals[ $type ] = count( $list ); |
| 1901 | |
| 1902 | if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'active', 'inactive', 'search' ) ) ) |
| 1903 | $status = 'all'; |
| 1904 | |
| 1905 | $this->items = array(); |
| 1906 | foreach ( $extensions[ $status ] as $extension_slug => $extension_data ) { |
| 1907 | // Translate, Don't Apply Markup, Sanitize HTML |
| 1908 | $this->items[ $extension_slug ] = array_merge( array( 'Extension Name' => $extension_data['class_name'] ), _get_plugin_data_markup_translate( $extension_data['parent_plugin'], $extension_data['parent_plugin_data'], false, true ) ); |
| 1909 | } |
| 1910 | |
| 1911 | $total_this_page = $totals[ $status ]; |
| 1912 | |
| 1913 | if ( $orderby ) { |
| 1914 | $orderby = ucfirst( $orderby ); |
| 1915 | $order = strtoupper( $order ); |
| 1916 | |
| 1917 | uasort( $this->items, array( &$this, '_order_callback' ) ); |
| 1918 | } |
| 1919 | |
| 1920 | $extensions_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 20 ); |
| 1921 | |
| 1922 | $start = ( $page - 1 ) * $extensions_per_page; |
| 1923 | |
| 1924 | if ( $total_this_page > $extensions_per_page ) |
| 1925 | $this->items = array_slice( $this->items, $start, $extensions_per_page ); |
| 1926 | |
| 1927 | $this->set_pagination_args( array( |
| 1928 | 'total_items' => $total_this_page, |
| 1929 | 'per_page' => $extensions_per_page, |
| 1930 | ) ); |
| 1931 | } |
| 1932 | |
| 1933 | function _search_callback( $extensions ) { |
| 1934 | static $term; |
| 1935 | if ( is_null( $term ) ) |
| 1936 | $term = stripslashes_deep( $_REQUEST['s'] ); |
| 1937 | |
| 1938 | foreach ( $extensions as $key => $value ) { |
| 1939 | |
| 1940 | switch( $key ){ |
| 1941 | case 'settings' : |
| 1942 | case 'parent_plugin' : |
| 1943 | continue; |
| 1944 | break; |
| 1945 | |
| 1946 | case 'class_name' : |
| 1947 | if ( stripos( $value, $term ) !== false ) |
| 1948 | return true; |
| 1949 | break; |
| 1950 | |
| 1951 | case 'parent_plugin_data' : |
| 1952 | if ( stripos( $value['Name'], $term ) !== false ) |
| 1953 | return true; |
| 1954 | break; |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
| 1961 | function _order_callback( $extension_a, $extension_b ) { |
| 1962 | global $orderby, $order; |
| 1963 | |
| 1964 | $a = $extension_a[$orderby]; |
| 1965 | $b = $extension_b[$orderby]; |
| 1966 | |
| 1967 | if ( $a == $b ) |
| 1968 | return 0; |
| 1969 | |
| 1970 | if ( 'DESC' == $order ) |
| 1971 | return ( $a < $b ) ? 1 : -1; |
| 1972 | else |
| 1973 | return ( $a < $b ) ? -1 : 1; |
| 1974 | } |
| 1975 | |
| 1976 | function no_items() { |
| 1977 | global $extensions, $status; |
| 1978 | |
| 1979 | if ( !empty( $extensions ) ) { |
| 1980 | |
| 1981 | switch( $status ) { |
| 1982 | case 'inactive' : |
| 1983 | $text = __( 'inactive', 'buddypress' ); |
| 1984 | break; |
| 1985 | case 'active' : |
| 1986 | $text = __( 'active', 'buddypress' ); |
| 1987 | break; |
| 1988 | case 'all' : |
| 1989 | default: |
| 1990 | $text = ''; |
| 1991 | break; |
| 1992 | } |
| 1993 | |
| 1994 | printf( __( 'No %s group extensions found.', 'buddypress' ), $text ); |
| 1995 | } else |
| 1996 | _e( 'You do not appear to have any group extensions available at this time.', 'buddypress' ); |
| 1997 | } |
| 1998 | |
| 1999 | /** |
| 2000 | * Display the search box. |
| 2001 | * |
| 2002 | * @since 3.1.0 |
| 2003 | * @access public |
| 2004 | * |
| 2005 | * @param string $text The search button text |
| 2006 | * @param string $input_id The search input id |
| 2007 | */ |
| 2008 | function search_box( $text, $input_id ) { |
| 2009 | if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) |
| 2010 | return; |
| 2011 | |
| 2012 | $input_id = $input_id . '-search-input'; |
| 2013 | |
| 2014 | if ( ! empty( $_REQUEST['orderby'] ) ) |
| 2015 | echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
| 2016 | if ( ! empty( $_REQUEST['order'] ) ) |
| 2017 | echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
| 2018 | ?> |
| 2019 | <p class="search-box"> |
| 2020 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
| 2021 | <input type="hidden" name="page" value="bp-groups-extensions"/> |
| 2022 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php _e( 'Plugin or Group Extension', 'buddypress' );?>" /> |
| 2023 | <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?> |
| 2024 | </p> |
| 2025 | <?php |
| 2026 | } |
| 2027 | |
| 2028 | function get_columns() { |
| 2029 | global $status; |
| 2030 | |
| 2031 | return array( |
| 2032 | 'cb' => '<input type="checkbox" />', |
| 2033 | 'name' => __( 'Group Extensions', 'buddypress' ), |
| 2034 | 'description' => __( 'Plugin Description', 'buddypress' ) |
| 2035 | ); |
| 2036 | } |
| 2037 | |
| 2038 | function get_sortable_columns() { |
| 2039 | return array(); |
| 2040 | } |
| 2041 | |
| 2042 | function get_views() { |
| 2043 | global $totals, $status; |
| 2044 | |
| 2045 | $url_base = bp_get_admin_url( 'admin.php?page=bp-groups-extensions' ); |
| 2046 | |
| 2047 | $status_links = array(); |
| 2048 | foreach ( $totals as $type => $count ) { |
| 2049 | if ( !$count ) |
| 2050 | continue; |
| 2051 | |
| 2052 | switch ( $type ) { |
| 2053 | case 'all': |
| 2054 | $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'group extensions' ); |
| 2055 | break; |
| 2056 | case 'active': |
| 2057 | $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count ); |
| 2058 | break; |
| 2059 | case 'inactive': |
| 2060 | $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); |
| 2061 | break; |
| 2062 | } |
| 2063 | |
| 2064 | if ( 'search' != $type ) { |
| 2065 | $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", |
| 2066 | add_query_arg('extension_status', $type, $url_base), |
| 2067 | ( $type == $status ) ? ' class="current"' : '', |
| 2068 | sprintf( $text, number_format_i18n( $count ) ) |
| 2069 | ); |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | return $status_links; |
| 2074 | } |
| 2075 | |
| 2076 | function get_bulk_actions() { |
| 2077 | global $status; |
| 2078 | |
| 2079 | $actions = array(); |
| 2080 | |
| 2081 | if ( 'active' != $status ) |
| 2082 | $actions['activate-selected'] = __( 'Activate' ); |
| 2083 | |
| 2084 | if ( 'inactive' != $status && 'recent' != $status ) |
| 2085 | $actions['deactivate-selected'] = __( 'Deactivate' ); |
| 2086 | |
| 2087 | |
| 2088 | return $actions; |
| 2089 | } |
| 2090 | |
| 2091 | function bulk_actions() { |
| 2092 | global $status; |
| 2093 | |
| 2094 | parent::bulk_actions(); |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | function current_action() { |
| 2099 | return parent::current_action(); |
| 2100 | } |
| 2101 | |
| 2102 | function display_rows() { |
| 2103 | global $status; |
| 2104 | |
| 2105 | foreach ( $this->items as $extension_slug => $extension_data ) { |
| 2106 | $this->single_row( $extension_slug, $extension_data ); |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | function single_row( $extension_slug, $extension_data ) { |
| 2111 | global $status, $page, $s, $totals; |
| 2112 | |
| 2113 | $context = $status; |
| 2114 | $screen = $this->screen; |
| 2115 | $base_url = bp_get_admin_url( 'admin.php?page=bp-groups-extensions' ); |
| 2116 | |
| 2117 | // preorder |
| 2118 | $actions = array( |
| 2119 | 'activate' => '', |
| 2120 | 'deactivate' => '', |
| 2121 | ); |
| 2122 | |
| 2123 | $is_inactive = ! bp_groups_is_extension_active( $extension_slug ); |
| 2124 | |
| 2125 | if ( $is_inactive ) { |
| 2126 | $activate_url = wp_nonce_url( $base_url . '&action=activate&extension=' . $extension_slug .'&extension_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bp-groups-extensions-activate' ); |
| 2127 | $actions['activate'] = '<a href="' . $activate_url . '" title="' . esc_attr__('Activate this extension', 'buddypress') . '">' . __('Activate', 'buddypress') . '</a>'; |
| 2128 | } else { |
| 2129 | $deactivate_url = wp_nonce_url( $base_url . '&action=deactivate&extension='. $extension_slug .'&extension_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bp-groups-extensions-deactivate' ); |
| 2130 | $actions['deactivate'] = '<a href="' . $deactivate_url . '" title="' . esc_attr__('Deactivate this extension', 'buddypress') . '" class="delete">' . __('Deactivate', 'buddypress') . '</a>'; |
| 2131 | } |
| 2132 | |
| 2133 | $actions = apply_filters( 'bp_groups_extensions_action_links', array_filter( $actions ), $extension_data, $context ); |
| 2134 | |
| 2135 | // end if $context |
| 2136 | $checkbox_id = "checkbox_" . md5($extension_data['Extension Name']); |
| 2137 | |
| 2138 | $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $extension_data['Extension Name'] ) . "</label>" |
| 2139 | . "<input type='checkbox' name='checked[]' value='" . esc_attr( $extension_slug ) . "' id='" . $checkbox_id . "' />"; |
| 2140 | |
| 2141 | $description = '<p>' . ( $extension_data['Description'] ? $extension_data['Description'] : ' ' ) . '</p>'; |
| 2142 | |
| 2143 | $extension_name = $extension_data['Extension Name']; |
| 2144 | $plugin_name = $extension_data['Name']; |
| 2145 | |
| 2146 | $id = sanitize_title( $extension_name ); |
| 2147 | $class = $is_inactive ? 'inactive' : 'active' ; |
| 2148 | |
| 2149 | echo "<tr id='$id' class='$class'>"; |
| 2150 | |
| 2151 | list( $columns, $hidden ) = $this->get_column_info(); |
| 2152 | |
| 2153 | foreach ( $columns as $column_name => $column_display_name ) { |
| 2154 | $style = ''; |
| 2155 | if ( in_array( $column_name, $hidden ) ) |
| 2156 | $style = ' style="display:none;"'; |
| 2157 | |
| 2158 | switch ( $column_name ) { |
| 2159 | case 'cb': |
| 2160 | echo "<th scope='row' class='check-column'>$checkbox</th>"; |
| 2161 | break; |
| 2162 | case 'name': |
| 2163 | echo "<td class='plugin-title'$style><strong>$extension_name</strong>"; |
| 2164 | echo $this->row_actions( $actions, true ); |
| 2165 | echo "</td>"; |
| 2166 | break; |
| 2167 | case 'description': |
| 2168 | echo "<td class='column-description desc'$style> |
| 2169 | <div class='plugin-description'><strong>$plugin_name</strong>$description</div></td>"; |
| 2170 | break; |
| 2171 | default: |
| 2172 | echo "<td class='$column_name column-$column_name'$style>"; |
| 2173 | do_action( 'manage_plugins_custom_column', $column_name, $extension_data ); |
| 2174 | echo "</td>"; |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | echo "</tr>"; |
| 2179 | |
| 2180 | do_action( 'bp_groups_extensions_after_extension_row', $extension_data, $status ); |
| 2181 | } |
| 2182 | } |