Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zilveer #541

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
625 changes: 314 additions & 311 deletions README.md

Large diffs are not rendered by default.

502 changes: 349 additions & 153 deletions admin/box-factory.php

Large diffs are not rendered by default.

456 changes: 228 additions & 228 deletions admin/box.css

Large diffs are not rendered by default.

946 changes: 473 additions & 473 deletions admin/box.js

Large diffs are not rendered by default.

652 changes: 326 additions & 326 deletions admin/box.php

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions admin/column-factory.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php

class P2P_Column_Factory extends P2P_Factory {

protected $key = 'admin_column';

function __construct() {
parent::__construct();

add_action( 'load-edit.php', array( $this, 'add_items' ) );
add_action( 'load-users.php', array( $this, 'add_items' ) );
}

function add_item( $directed, $object_type, $post_type, $title ) {
$class = 'P2P_Column_' . ucfirst( $object_type );
$column = new $class( $directed );

$screen = get_current_screen();

add_filter( "manage_{$screen->id}_columns", array( $column, 'add_column' ) );
add_action( 'admin_print_styles', array( $column, 'styles' ) );
}
}

<?php
class P2P_Column_Factory extends P2P_Factory {
protected $key = 'admin_column';
function __construct() {
parent::__construct();
add_action( 'load-edit.php', array( $this, 'add_items' ) );
add_action( 'load-users.php', array( $this, 'add_items' ) );
}
function add_item( $directed, $object_type, $post_type, $title ) {
$class = 'P2P_Column_' . ucfirst( $object_type );
$column = new $class( $directed );
$screen = get_current_screen();
add_filter( "manage_{$screen->id}_columns", array( $column, 'add_column' ) );
add_action( 'admin_print_styles', array( $column, 'styles' ) );
}
}
72 changes: 36 additions & 36 deletions admin/column-post.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?php

class P2P_Column_Post extends P2P_Column {

function __construct( $directed ) {
parent::__construct( $directed );

$screen = get_current_screen();

add_action( "manage_{$screen->post_type}_posts_custom_column", array( $this, 'display_column' ), 10, 2 );
}

protected function get_items() {
global $wp_query;

return $wp_query->posts;
}

function get_admin_link( $item ) {
$args = array(
'connected_type' => $this->ctype->name,
'connected_direction' => $this->ctype->flip_direction()->get_direction(),
'connected_items' => $item->get_id(),
'post_type' => get_current_screen()->post_type
);

$admin_link = apply_filters( "p2p_post_admin_column_link", add_query_arg( $args, admin_url( 'edit.php' ) ), $item );

return $admin_link;
}

function display_column( $column, $item_id ) {
echo parent::render_column( $column, $item_id );
}
}

<?php
class P2P_Column_Post extends P2P_Column {
function __construct( $directed ) {
parent::__construct( $directed );
$screen = get_current_screen();
add_action( "manage_{$screen->post_type}_posts_custom_column", array( $this, 'display_column' ), 10, 2 );
}
protected function get_items() {
global $wp_query;
return $wp_query->posts;
}
function get_admin_link( $item ) {
$args = array(
'connected_type' => $this->ctype->name,
'connected_direction' => $this->ctype->flip_direction()->get_direction(),
'connected_items' => $item->get_id(),
'post_type' => get_current_screen()->post_type
);
$admin_link = apply_filters( "p2p_post_admin_column_link", add_query_arg( $args, admin_url( 'edit.php' ) ), $item );
return $admin_link;
}
function display_column( $column, $item_id ) {
echo parent::render_column( $column, $item_id );
}
}
96 changes: 48 additions & 48 deletions admin/column-user.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
<?php

class P2P_Column_User extends P2P_Column {

function __construct( $directed ) {
parent::__construct( $directed );

add_action( 'pre_user_query', array( __CLASS__, 'user_query' ), 9 );

add_filter( 'manage_users_custom_column', array( $this, 'display_column' ), 10, 3 );
}

protected function get_items() {
global $wp_list_table;

return $wp_list_table->items;
}

// Add the query vars to the global user query (on the user admin screen)
static function user_query( $query ) {
if ( isset( $query->_p2p_capture ) )
return;

// Don't overwrite existing P2P query
if ( isset( $query->query_vars['connected_type'] ) )
return;

_p2p_append( $query->query_vars, wp_array_slice_assoc( $_GET,
P2P_URL_Query::get_custom_qv() ) );
}

function get_admin_link( $item ) {
$args = array(
'connected_type' => $this->ctype->name,
'connected_direction' => $this->ctype->flip_direction()->get_direction(),
'connected_items' => $item->get_id(),
);

$admin_link = apply_filters( "p2p_user_admin_column_link", add_query_arg( $args, admin_url( 'users.php' ) ), $item );

return $admin_link;
}

function display_column( $content, $column, $item_id ) {
return $content . parent::render_column( $column, $item_id );
}
}

<?php
class P2P_Column_User extends P2P_Column {
function __construct( $directed ) {
parent::__construct( $directed );
add_action( 'pre_user_query', array( __CLASS__, 'user_query' ), 9 );
add_filter( 'manage_users_custom_column', array( $this, 'display_column' ), 10, 3 );
}
protected function get_items() {
global $wp_list_table;
return $wp_list_table->items;
}
// Add the query vars to the global user query (on the user admin screen)
static function user_query( $query ) {
if ( isset( $query->_p2p_capture ) )
return;
// Don't overwrite existing P2P query
if ( isset( $query->query_vars['connected_type'] ) )
return;
_p2p_append( $query->query_vars, wp_array_slice_assoc( $_GET,
P2P_URL_Query::get_custom_qv() ) );
}
function get_admin_link( $item ) {
$args = array(
'connected_type' => $this->ctype->name,
'connected_direction' => $this->ctype->flip_direction()->get_direction(),
'connected_items' => $item->get_id(),
);
$admin_link = apply_filters( "p2p_user_admin_column_link", add_query_arg( $args, admin_url( 'users.php' ) ), $item );
return $admin_link;
}
function display_column( $content, $column, $item_id ) {
return $content . parent::render_column( $column, $item_id );
}
}
154 changes: 77 additions & 77 deletions admin/column.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
<?php

/**
* A column in a list table in wp-admin
*/
abstract class P2P_Column {

protected $ctype;

protected $connected = array();

function __construct( $directed ) {
$this->ctype = $directed;

$this->column_id = sprintf( 'p2p-%s-%s',
$this->ctype->get_direction(),
$this->ctype->name
);
}

function add_column( $columns ) {
$this->prepare_items();

$labels = $this->ctype->get( 'current', 'labels' );

$title = isset( $labels->column_title )
? $labels->column_title
: $this->ctype->get( 'current', 'title' );

return array_splice( $columns, 0, -1 ) + array( $this->column_id => $title ) + $columns;
}

protected abstract function get_items();

protected function prepare_items() {
$items = $this->get_items();

$extra_qv = array(
'p2p:per_page' => -1,
'p2p:context' => 'admin_column'
);

$connected = $this->ctype->get_connected( $items, $extra_qv, 'abstract' );

$this->connected = scb_list_group_by( $connected->items, '_p2p_get_other_id' );
}

function styles() {
?>
<style type="text/css">
.column-<?php echo $this->column_id; ?> ul {
margin-top: 0;
margin-bottom: 0;
}
</style>
<?php
}

abstract function get_admin_link( $item );

protected function render_column( $column, $item_id ) {
if ( $this->column_id != $column )
return;

if ( !isset( $this->connected[ $item_id ] ) )
return;

$out = '<ul>';
foreach ( $this->connected[ $item_id ] as $item ) {
$out .= html( 'li', html_link( $this->get_admin_link( $item ), $item->get_title() ) );
}
$out .= '</ul>';

return $out;
}
}

<?php
/**
* A column in a list table in wp-admin
*/
abstract class P2P_Column {
protected $ctype;
protected $connected = array();
function __construct( $directed ) {
$this->ctype = $directed;
$this->column_id = sprintf( 'p2p-%s-%s',
$this->ctype->get_direction(),
$this->ctype->name
);
}
function add_column( $columns ) {
$this->prepare_items();
$labels = $this->ctype->get( 'current', 'labels' );
$title = isset( $labels->column_title )
? $labels->column_title
: $this->ctype->get( 'current', 'title' );
return array_splice( $columns, 0, -1 ) + array( $this->column_id => $title ) + $columns;
}
protected abstract function get_items();
protected function prepare_items() {
$items = $this->get_items();
$extra_qv = array(
'p2p:per_page' => -1,
'p2p:context' => 'admin_column'
);
$connected = $this->ctype->get_connected( $items, $extra_qv, 'abstract' );
$this->connected = scb_list_group_by( $connected->items, '_p2p_get_other_id' );
}
function styles() {
?>
<style type="text/css">
.column-<?php echo $this->column_id; ?> ul {
margin-top: 0;
margin-bottom: 0;
}
</style>
<?php
}
abstract function get_admin_link( $item );
protected function render_column( $column, $item_id ) {
if ( $this->column_id != $column )
return;
if ( !isset( $this->connected[ $item_id ] ) )
return;
$out = '<ul>';
foreach ( $this->connected[ $item_id ] as $item ) {
$out .= html( 'li', html_link( $this->get_admin_link( $item ), $item->get_title() ) );
}
$out .= '</ul>';
return $out;
}
}
Loading