Skip to content

Commit

Permalink
first pass at autoloading core classes
Browse files Browse the repository at this point in the history
  • Loading branch information
scribu committed Jan 14, 2013
1 parent b06ceb2 commit 34edc45
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 456 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions item-any.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class P2P_Item_Any extends P2P_Item {

function __construct() {}

function get_permalink() {}

function get_title() {}

function get_object() {
return 'any';
}

function get_id() {
return false;
}
}

12 changes: 12 additions & 0 deletions item-attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

class P2P_Item_Attachment extends P2P_Item_Post {

function get_title() {
if( wp_attachment_is_image( $this->item->ID ) )
return wp_get_attachment_image( $this->item->ID, 'thumbnail', false );

return get_the_title( $this->item );
}
}

17 changes: 17 additions & 0 deletions item-post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class P2P_Item_Post extends P2P_Item {

function get_title() {
return get_the_title( $this->item );
}

function get_permalink() {
return get_permalink( $this->item );
}

function get_editlink() {
return get_edit_post_link( $this->item );
}
}

41 changes: 41 additions & 0 deletions item-user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

class P2P_Item_User extends P2P_Item {

function get_title() {
return $this->item->display_name;
}

function get_permalink() {
return get_author_posts_url( $this->item->ID );
}

function get_editlink() {
return get_edit_user_link( $this->item->ID );
}
}


// WP < 3.5
if ( !function_exists( 'get_edit_user_link' ) ) :
function get_edit_user_link( $user_id = null ) {
if ( ! $user_id )
$user_id = get_current_user_id();

if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
return '';

$user = new WP_User( $user_id );

if ( ! $user->exists() )
return '';

if ( get_current_user_id() == $user->ID )
$link = get_edit_profile_url( $user->ID );
else
$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );

return apply_filters( 'get_edit_user_link', $link, $user->ID );
}
endif;

85 changes: 0 additions & 85 deletions item.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,88 +32,3 @@ abstract function get_permalink();
abstract function get_title();
}


class P2P_Item_Any extends P2P_Item {

function __construct() {}

function get_permalink() {}

function get_title() {}

function get_object() {
return 'any';
}

function get_id() {
return false;
}
}


class P2P_Item_Post extends P2P_Item {

function get_title() {
return get_the_title( $this->item );
}

function get_permalink() {
return get_permalink( $this->item );
}

function get_editlink() {
return get_edit_post_link( $this->item );
}
}


class P2P_Item_Attachment extends P2P_Item_Post {

function get_title() {
if( wp_attachment_is_image( $this->item->ID ) )
return wp_get_attachment_image( $this->item->ID, 'thumbnail', false );

return get_the_title( $this->item );
}
}


class P2P_Item_User extends P2P_Item {

function get_title() {
return $this->item->display_name;
}

function get_permalink() {
return get_author_posts_url( $this->item->ID );
}

function get_editlink() {
return get_edit_user_link( $this->item->ID );
}
}


// WP < 3.5
if ( !function_exists( 'get_edit_user_link' ) ) :
function get_edit_user_link( $user_id = null ) {
if ( ! $user_id )
$user_id = get_current_user_id();

if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
return '';

$user = new WP_User( $user_id );

if ( ! $user->exists() )
return '';

if ( get_current_user_id() == $user->ID )
$link = get_edit_profile_url( $user->ID );
else
$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );

return apply_filters( 'get_edit_user_link', $link, $user->ID );
}
endif;

4 changes: 1 addition & 3 deletions query-post.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class P2P_Post_Query {
class P2P_Query_Post {

static function init() {
add_action( 'parse_query', array( __CLASS__, 'parse_query' ), 20 );
Expand Down Expand Up @@ -59,5 +59,3 @@ static function cache_p2p_meta( $the_posts, $wp_query ) {
}
}

P2P_Post_Query::init();

4 changes: 1 addition & 3 deletions query-user.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class P2P_User_Query {
class P2P_Query_User {

static function init() {
add_action( 'pre_user_query', array( __CLASS__, 'pre_user_query' ), 20 );
Expand Down Expand Up @@ -43,5 +43,3 @@ static function pre_user_query( $query ) {
}
}

P2P_User_Query::init();

35 changes: 35 additions & 0 deletions shortcodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class P2P_Shortcodes {

static function init() {
add_shortcode( 'p2p_connected', array( __CLASS__, 'connected' ) );
add_shortcode( 'p2p_related', array( __CLASS__, 'related' ) );
}

static function connected( $attr ) {
return self::get_list( $attr, 'get_connected' );
}

static function related( $attr ) {
return self::get_list( $attr, 'get_related' );
}

private static function get_list( $attr, $method ) {
global $post;

$attr = shortcode_atts( array(
'type' => '',
'mode' => 'ul',
), $attr );

return _p2p_get_list( array(
'ctype' => $attr['type'],
'method' => $method,
'item' => $post,
'mode' => $attr['mode'],
'context' => 'shortcode'
) );
}
}

23 changes: 23 additions & 0 deletions side-attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class P2P_Side_Attachment extends P2P_Side_Post {

protected $item_type = 'P2P_Item_Attachment';

function __construct( $query_vars ) {
$this->query_vars = $query_vars;

$this->query_vars['post_type'] = array( 'attachment' );
}

function can_create_item() {
return false;
}

function get_base_qv( $q ) {
return array_merge( parent::get_base_qv( $q ), array(
'post_status' => 'inherit'
) );
}
}

Loading

0 comments on commit 34edc45

Please sign in to comment.