LinkCount.php
1.53 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
61
62
63
64
<?php
namespace ACP\Column\Post;
use AC;
use ACP\ConditionalFormat\Formattable;
use ACP\ConditionalFormat\IntegerFormattableTrait;
use ACP\Export;
use ACP\Settings;
use ACP\Sorting;
class LinkCount extends AC\Column
implements Export\Exportable, Sorting\Sortable, Formattable {
use IntegerFormattableTrait;
public function __construct() {
$this->set_type( 'column-linkcount' )
->set_label( __( 'Link Count', 'codepress-admin-columns' ) );
}
public function get_raw_value( $id ) {
return ac_helper()->html->get_internal_external_links(
get_post_field( 'post_content', $id ),
$this->get_internal_domains()
);
}
private function get_internal_domains(): array {
return (array) apply_filters( 'ac/column/linkcount/domains', [ home_url() ] );
}
public function register_settings() {
$this->add_setting( new Settings\Column\LinkCount( $this ) );
}
public function is_valid() {
return class_exists( 'DOMDocument', false );
}
public function export() {
return new Export\Model\Post\LinkCount( $this );
}
private function get_link_count_type() {
$setting = $this->get_setting( 'link_count_type' );
return $setting instanceof Settings\Column\LinkCount
? $setting->get_link_count_type()
: null;
}
public function sorting() {
switch ( $this->get_link_count_type() ) {
case 'internal' :
return new Sorting\Model\Post\LinkCount( $this->get_internal_domains() );
case 'external' :
return new Sorting\Model\Disabled();
default :
return new Sorting\Model\Post\LinkCount( [ 'http' ] );
}
}
}