Пример #1
0
/** @internal */
function _p2p_extract_post_types($sides)
{
    $ptypes = array();
    foreach ($sides as $side) {
        if ('post' == $side->get_object_type()) {
            _p2p_append($ptypes, $side->query_vars['post_type']);
        }
    }
    return array_unique($ptypes);
}
Пример #2
0
 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()));
 }
Пример #3
0
 static function massage_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, self::get_qv());
 }
Пример #4
0
 static function user_query($query)
 {
     if (!function_exists('get_current_screen')) {
         return;
     }
     $current_screen = get_current_screen();
     if ($current_screen && 'users' != $current_screen->id) {
         return;
     }
     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, self::get_custom_qv()));
 }
Пример #5
0
/** @internal */
function _p2p_get_list($args)
{
    extract($args);
    $ctype = p2p_type($ctype);
    if (!$ctype) {
        trigger_error(sprintf("Unregistered connection type '%s'.", $ctype), E_USER_WARNING);
        return '';
    }
    $directed = $ctype->find_direction($item);
    if (!$directed) {
        return '';
    }
    $extra_qv = array('p2p:per_page' => -1, 'p2p:context' => $context);
    $connected = $directed->{$method}($item, $extra_qv, 'abstract');
    $args = array('before_list' => '<ul id="' . $ctype->name . '_list">', 'echo' => false);
    if ('ol' == $mode) {
        _p2p_append($args, array('before_list' => '<ol id="' . $ctype->name . '_list">', 'after_list' => '</ol>'));
    }
    return apply_filters("p2p_{$context}_html", $connected->render($args), $connected, $directed);
}
 protected function get_non_connectable($item, $extra_qv)
 {
     $to_exclude = array();
     if ('one' == $this->get('current', 'cardinality')) {
         $to_check = 'any';
     } elseif (!$this->duplicate_connections) {
         $to_check = $item;
     } else {
         return $to_exclude;
     }
     $extra_qv['fields'] = 'ids';
     $extra_qv['p2p:per_page'] = -1;
     $already_connected = $this->get_connected($to_check, $extra_qv, 'abstract')->items;
     _p2p_append($to_exclude, $already_connected);
     return $to_exclude;
 }
Пример #7
0
 private function get_non_connectable($item_id)
 {
     $to_exclude = array();
     if ($this->indeterminate && !$this->self_connections) {
         $to_exclude[] = $item_id;
     }
     if ('one' == $this->get_current('cardinality')) {
         _p2p_append($to_exclude, $this->get_connections(array('fields' => 'object_id')));
     }
     if ($this->prevent_duplicates) {
         _p2p_append($to_exclude, $this->get_connections(array('from' => $item_id, 'fields' => 'object_id')));
     }
     return $to_exclude;
 }
 /**
  * Get a list of posts that could be connected to a given post.
  *
  * @param int $post_id A post id.
  */
 public function get_connectable($item_id, $page, $search)
 {
     $to_exclude = array();
     if ('one' == $this->get_current('cardinality')) {
         _p2p_append($to_exclude, p2p_get_connections($this->name, array('direction' => 'to' == $this->direction ? 'from' : 'to', 'fields' => 'object_id')));
     }
     if ($this->prevent_duplicates) {
         _p2p_append($to_exclude, p2p_get_connections($this->name, array('direction' => $this->direction, 'from' => $item_id, 'fields' => 'object_id')));
     }
     return $this->get_opposite('side')->get_connectable($item_id, $page, $search, $to_exclude, $this);
 }