WordPress.org

Plugin Directory

Changeset 629142


Ignore:
Timestamp:
11/23/12 20:08:29 (17 months ago)
Author:
scribu
Message:

deploy from git

Location:
posts-to-posts/trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • posts-to-posts/trunk/CONTRIBUTING.md

    r604130 r629142  
    1515Don't modify `admin/box.js` directly. Instead: 
    1616 
    17 - [Install node.js](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) and [npm](http://npmjs.org/). 
     17- [Install node.js](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager). 
    1818 
    1919- Install [CoffeeScript](http://coffeescript.org): 
     
    3434 
    35351. Install [PHPUnit](https://github.com/sebastianbergmann/phpunit/). 
    36 2. Install the WP testing suite: http://make.wordpress.org/core/handbook/automated-testing/ 
     362. Create `tests/wp-tests-config.php` file. ([sample](https://unit-tests.svn.wordpress.org/trunk/wp-tests-config-sample.php)) 
    37373. [Install the scbFramework](https://github.com/scribu/wp-scb-framework/wiki) in the mu-plugins dir. 
    38 4. Run `./bin/test /path/to/wp-tests 
     384. Run `./bin/test` 
  • posts-to-posts/trunk/admin/box-factory.php

    r599848 r629142  
    66 
    77    function __construct() { 
    8         add_filter( 'p2p_connection_type_args', array( $this, 'filter_ctypes' ) ); 
     8        add_action( 'p2p_registered_connection_type', array( $this, 'filter_ctypes' ), 10, 2 ); 
    99 
    1010        add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); 
     
    1313    } 
    1414 
    15     function filter_ctypes( $args ) { 
     15    function filter_ctypes( $ctype, $args ) { 
    1616        if ( isset( $args['admin_box'] ) ) { 
    1717            $box_args = _p2p_pluck( $args, 'admin_box' ); 
     
    3535        ) ); 
    3636 
    37         $this->register( $args['name'], $box_args ); 
     37        $this->register( $ctype->name, $box_args ); 
    3838 
    3939        return $args; 
  • posts-to-posts/trunk/admin/box.php

    r596521 r629142  
    1212 
    1313    private $columns; 
     14 
     15    private static $enqueued_scripts = false; 
    1416 
    1517    private static $admin_box_qv = array( 
     
    3032 
    3133    public function init_scripts() { 
     34 
     35        if ( self::$enqueued_scripts ) 
     36            return; 
     37 
    3238        wp_enqueue_style( 'p2p-box', plugins_url( 'box.css', __FILE__ ), array(), P2P_PLUGIN_VERSION ); 
    3339 
     
    3844            'deleteConfirmMessage' => __( 'Are you sure you want to delete all connections?', P2P_TEXTDOMAIN ), 
    3945        ) ); 
     46 
     47        self::$enqueued_scripts = true; 
     48 
    4049    } 
    4150 
  • posts-to-posts/trunk/admin/column-factory.php

    r574924 r629142  
    44 
    55    function __construct() { 
    6         add_filter( 'p2p_connection_type_args', array( $this, 'filter_ctypes' ) ); 
     6        add_action( 'p2p_registered_connection_type', array( $this, 'filter_ctypes' ), 10, 2 ); 
    77 
    88        add_action( 'admin_print_styles', array( $this, 'add_columns' ) ); 
    99    } 
    1010 
    11     function filter_ctypes( $args ) { 
     11    function filter_ctypes( $ctype, $args ) { 
    1212        if ( isset( $args['admin_column'] ) ) { 
    1313            $column_args = _p2p_pluck( $args, 'admin_column' ); 
     
    2222        ) ); 
    2323 
    24         $this->register( $args['name'], $column_args ); 
     24        $this->register( $ctype->name, $column_args ); 
    2525 
    2626        return $args; 
  • posts-to-posts/trunk/admin/column.php

    r593509 r629142  
    99    function __construct( $directed, $items ) { 
    1010        $this->ctype = $directed; 
     11        $this->column_id = sprintf( 'p2p-%s-%s', 
     12            $this->ctype->get_direction(), 
     13            $this->ctype->name 
     14        ); 
    1115 
    1216        $extra_qv = array( 
     
    2529 
    2630    function add_column( $columns ) { 
    27         $this->column_id = sprintf( 'p2p-%s-%s', 
    28             $this->ctype->get_direction(), 
    29             $this->ctype->name 
    30         ); 
    3131 
    3232        $columns[ $this->column_id ] = $this->ctype->get( 'current', 'title' ); 
     
    3838?> 
    3939<style type="text/css"> 
    40 .column-<?php echo $this->ctype->name; ?> ul { 
     40.column-<?php echo $this->column_id; ?> ul { 
    4141    margin-top: 0; 
    4242    margin-bottom: 0; 
  • posts-to-posts/trunk/admin/factory.php

    r598601 r629142  
    2525            $directions = self::determine_directions( $ctype, $object_type, $post_type, $args->show ); 
    2626 
    27             $title = $ctype->title; 
    28  
    29             if ( count( $directions ) > 1 && $title['from'] == $title['to'] ) { 
    30                 $title['from'] .= __( ' (from)', P2P_TEXTDOMAIN ); 
    31                 $title['to']   .= __( ' (to)', P2P_TEXTDOMAIN ); 
    32             } 
     27            $title = self::get_title( $directions, $ctype ); 
    3328 
    3429            foreach ( $directions as $direction ) { 
     
    4035            } 
    4136        } 
     37    } 
     38 
     39    protected static function get_title( $directions, $ctype ) { 
     40        $title = array( 
     41            'from' => $ctype->get_field( 'title', 'from' ), 
     42            'to' => $ctype->get_field( 'title', 'to' ) 
     43        ); 
     44 
     45        if ( count( $directions ) > 1 && $title['from'] == $title['to'] ) { 
     46            $title['from'] .= __( ' (from)', P2P_TEXTDOMAIN ); 
     47            $title['to']   .= __( ' (to)', P2P_TEXTDOMAIN ); 
     48        } 
     49 
     50        return $title; 
    4251    } 
    4352 
  • posts-to-posts/trunk/command.php

    r604130 r629142  
    55class P2P_CLI_Command extends WP_CLI_Command { 
    66 
     7    /** 
     8     * List registered connection types. 
     9     * 
     10     * @subcommand connection-types 
     11     */ 
    712    function connection_types() { 
    813        foreach ( P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype ) { 
     
    1116    } 
    1217 
     18    /** 
     19     * Generate connections for a specific connection type. 
     20     * 
     21     * @subcommand generate-connections 
     22     * @synopsis <connection-type> [--items] 
     23     */ 
    1324    function generate_connections( $args, $assoc_args ) { 
    14         if ( empty( $args ) ) { 
    15             WP_CLI::line( "usage: wp p2p " . __FUNCTION__ . " <connection-type>" ); 
    16             exit; 
    17         } 
    18  
    1925        list( $connection_type ) = $args; 
    2026 
     
    6470    } 
    6571 
     72    /** 
     73     * Set up the example connections. 
     74     * 
     75     * @subcommand setup-example 
     76     */ 
    6677    function setup_example() { 
    6778        $ctype = p2p_type( 'actor_movie' ); 
  • posts-to-posts/trunk/core/api.php

    r599761 r629142  
    7878    } 
    7979 
    80     return P2P_Connection_Type_Factory::register( $args ); 
     80    $ctype = P2P_Connection_Type_Factory::register( $args ); 
     81 
     82    do_action( 'p2p_registered_connection_type', $ctype, $args ); 
     83 
     84    return $ctype; 
    8185} 
    8286 
  • posts-to-posts/trunk/core/directed-type.php

    r599761 r629142  
    3535    } 
    3636 
    37     public function get( $side, $key ) { 
     37    public function get( $side, $field ) { 
    3838        static $map = array( 
    3939            'current' => array( 
     
    4949        ); 
    5050 
    51         $arg = $this->ctype->$key; 
    52  
    53         return $arg[ $map[ $side ][ $this->direction ] ]; 
     51        return $this->ctype->get_field( $field, $map[ $side ][ $this->direction ] ); 
    5452    } 
    5553 
     
    165163 
    166164        $extra_qv['fields'] = 'ids'; 
     165        $extra_qv['p2p:per_page'] = -1; 
     166 
    167167        $already_connected = $this->get_connected( $to_check, $extra_qv, 'abstract' )->items; 
    168168 
  • posts-to-posts/trunk/core/side.php

    r599848 r629142  
    102102 
    103103    function get_labels() { 
    104         return get_object_vars( $this->get_ptype()->labels ); 
     104        return $this->get_ptype()->labels; 
    105105    } 
    106106 
     
    167167 
    168168    protected function recognize( $arg ) { 
     169        if ( is_object( $arg ) && !isset( $arg->post_type ) ) 
     170            return false; 
     171 
    169172        $post = get_post( $arg ); 
    170173 
     
    230233 
    231234    function get_labels() { 
    232         return array( 
     235        return (object) array( 
    233236            'singular_name' => __( 'User', P2P_TEXTDOMAIN ), 
    234237            'search_items' => __( 'Search Users', P2P_TEXTDOMAIN ), 
  • posts-to-posts/trunk/core/type-factory.php

    r598601 r629142  
    66 
    77    public static function register( $args ) { 
    8         $args = wp_parse_args( $args, array( 
     8        $defaults = array( 
    99            'name' => false, 
    1010            'from_object' => 'post', 
     
    2424            'to_labels' => '', 
    2525            'reciprocal' => false, 
    26         ) ); 
     26        ); 
     27 
     28        $args = shortcode_atts( $defaults, $args ); 
    2729 
    2830        if ( strlen( $args['name'] ) > 44 ) { 
     
    4244        } 
    4345 
    44         if ( isset( self::$instances[ $args['name'] ] ) ) { 
    45             trigger_error( sprintf( "Connection type '%s' is already defined.", $args['name'] ), E_USER_NOTICE ); 
    46         } 
    47  
    4846        $args = apply_filters( 'p2p_connection_type_args', $args, $sides ); 
    4947 
    5048        $class = self::get_ctype_class( $sides, _p2p_pluck( $args, 'reciprocal' ) ); 
    5149 
    52         $ctype = new $class( $sides, $args ); 
     50        $ctype = new $class( $args, $sides ); 
    5351 
    5452        self::$instances[ $ctype->name ] = $ctype; 
  • posts-to-posts/trunk/core/type.php

    r598601 r629142  
    1111    public $cardinality; 
    1212 
    13     public $title; 
    14  
    1513    public $labels; 
    1614 
    17     public function __construct( $sides, $args ) { 
     15    protected $title; 
     16 
     17    public function __construct( $args, $sides ) { 
    1818        $this->side = $sides; 
    1919 
     
    2222        $this->set_cardinality( _p2p_pluck( $args, 'cardinality' ) ); 
    2323 
    24         $this->set_labels( $args ); 
    25  
    26         $this->title = $this->expand_title( _p2p_pluck( $args, 'title' ) ); 
     24        $labels = array(); 
     25        foreach ( array( 'from', 'to' ) as $key ) { 
     26            $labels[ $key ] = (array) _p2p_pluck( $args, $key . '_labels' ); 
     27        } 
     28 
     29        $this->labels = $labels; 
    2730 
    2831        $this->fields = $this->expand_fields( _p2p_pluck( $args, 'fields' ) ); 
     
    3134            $this->$key = $value; 
    3235        } 
     36    } 
     37 
     38    public function get_field( $field, $direction ) { 
     39        $value = $this->$field; 
     40 
     41        if ( 'title' == $field ) 
     42            return $this->expand_title( $value, $direction ); 
     43 
     44        if ( 'labels' == $field ) 
     45            return $this->expand_labels( $value, $direction ); 
     46 
     47        if ( false === $direction ) 
     48            return $value; 
     49 
     50        return $value[ $direction ]; 
    3351    } 
    3452 
     
    8098    } 
    8199 
    82     private function set_labels( &$args ) { 
    83         foreach ( array( 'from', 'to' ) as $key ) { 
    84             $labels = $this->side[ $key ]->get_labels(); 
    85             $labels['create'] = __( 'Create connections', P2P_TEXTDOMAIN ); 
    86  
    87             _p2p_append( $labels, (array) _p2p_pluck( $args, $key . '_labels' ) ); 
    88  
    89             $this->labels[ $key ] = (object) $labels; 
    90         } 
    91     } 
    92  
    93     private function expand_title( $title ) { 
    94         if ( $title && !is_array( $title ) ) { 
    95             return array( 
    96                 'from' => $title, 
    97                 'to' => $title, 
    98             ); 
    99         } 
    100  
    101         foreach ( array( 'from', 'to' ) as $key ) { 
    102             if ( isset( $title[$key] ) ) 
    103                 continue; 
    104  
    105             $other_key = ( 'from' == $key ) ? 'to' : 'from'; 
    106  
    107             $title[$key] = sprintf( 
    108                 __( 'Connected %s', P2P_TEXTDOMAIN ), 
    109                 $this->side[ $other_key ]->get_title() 
    110             ); 
    111         } 
    112  
    113         return $title; 
     100    private function expand_labels( $additional_labels, $key ) { 
     101        $additional_labels['create'] = __( 'Create connections', P2P_TEXTDOMAIN ); 
     102 
     103        $labels = clone $this->side[ $key ]->get_labels(); 
     104 
     105        foreach ( $additional_labels as $key => $var ) 
     106            $labels->$key = $var; 
     107 
     108        return $labels; 
     109    } 
     110 
     111    private function expand_title( $title, $key ) { 
     112        if ( $title && !is_array( $title ) ) 
     113            return $title; 
     114 
     115        if ( isset( $title[$key] ) ) 
     116            return $title[$key]; 
     117 
     118        $other_key = ( 'from' == $key ) ? 'to' : 'from'; 
     119 
     120        return sprintf( 
     121            __( 'Connected %s', P2P_TEXTDOMAIN ), 
     122            $this->side[ $other_key ]->get_title() 
     123        ); 
    114124    } 
    115125 
     
    377387        $label = "$from {$this->arrow} $to"; 
    378388 
    379         $title = $this->title[ 'from' ]; 
     389        $title = $this->get_field( 'title', 'from' ); 
    380390 
    381391        if ( $title ) 
  • posts-to-posts/trunk/core/url-query.php

    r596521 r629142  
    3737 
    3838        _p2p_append( $query->query_vars, wp_array_slice_assoc( $_GET, 
    39             P2P_URL_Query::get_custom_qv() ) ); 
     39            self::get_custom_qv() ) ); 
    4040    } 
    4141} 
  • posts-to-posts/trunk/debug-utils.php

    r604130 r629142  
    33// Tools for testing and debugging P2P 
    44 
    5 add_filter( 'p2p_connection_type_args', '_p2p_register_missing_post_types', 10, 2 ); 
     5add_action( 'p2p_registered_connection_type', '_p2p_register_missing_post_types' ); 
    66 
    7 function _p2p_register_missing_post_types( $args, $sides ) { 
    8     foreach ( _p2p_extract_post_types( $sides ) as $ptype ) { 
     7function _p2p_register_missing_post_types( $ctype ) { 
     8    foreach ( _p2p_extract_post_types( $ctype->side ) as $ptype ) { 
    99        if ( !post_type_exists( $ptype ) ) { 
    1010            _p2p_generate_post_type( $ptype ); 
    1111        } 
    1212    } 
    13  
    14     return $args; 
    1513} 
    1614 
  • posts-to-posts/trunk/debug.php

    r599761 r629142  
    22 
    33require_once __DIR__ . '/debug-utils.php'; 
    4  
    5 if ( defined( 'WP_CLI' ) ) 
    6     require_once __DIR__ . '/command.php'; 
    74 
    85add_action( 'p2p_init', array( 'P2P_Debug', 'init' ), 11 ); 
     
    118 
    129    function init() { 
     10        if ( defined( 'WP_CLI' ) ) 
     11            require_once __DIR__ . '/command.php'; 
     12 
    1313        self::posts_to_attachments(); 
    1414        self::posts_to_users(); 
     
    6464                    'default' => 'green' 
    6565                ), 
     66            ), 
     67            'admin_box' => array( 
     68                'context' => 'advanced' 
    6669            ), 
    6770            'sortable' => true, 
Note: See TracChangeset for help on using the changeset viewer.