LinkCount.php
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace ACP\Column\Post;
use AC;
use ACP\Export;
/**
* Depth of the current page (number of ancestors + 1)
* @since 2.3.4
*/
class LinkCount extends AC\Column
implements Export\Exportable {
public function __construct() {
$this->set_type( 'column-linkcount' );
$this->set_label( __( 'Link Count', 'codepress-admin-columns' ) );
}
/**
* @param int $id
*
* @return string
*/
public function get_value( $id ) {
$links = $this->get_raw_value( $id );
if ( ! $links ) {
return $this->get_empty_char();
}
$internal = count( $links[0] );
$external = count( $links[1] );
return sprintf( '%s | %s',
ac_helper()->html->tooltip( $internal, __( 'Internal Links', 'codepress-admin-columns' ) ),
ac_helper()->html->tooltip( $external, __( 'External Links', 'codepress-admin-columns' ) )
);
}
/**
* @param $id
*
* @return array|false
*/
public function get_raw_value( $id ) {
$internal_domains = apply_filters( 'ac/column/linkcount/domains', [ home_url() ] );
return ac_helper()->html->get_internal_external_links( get_post_field( 'post_content', $id ), $internal_domains );
}
public function is_valid() {
return class_exists( 'DOMDocument', false );
}
public function export() {
return new Export\Model\Post\LinkCount( $this );
}
}