forked from lloc/Multisite-Language-Switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMslsBlog.php
More file actions
127 lines (114 loc) · 2.53 KB
/
Copy pathMslsBlog.php
File metadata and controls
127 lines (114 loc) · 2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* MslsBlog
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/
/**
* Internal representation of a blog
* @property int $userblog_id
* @package Msls
*/
class MslsBlog {
/**
* WordPress generates such an object
* @var StdClass
*/
private $obj;
/**
* Language-code eg. de_DE
* @var string
*/
private $language;
/**
* Description eg. Deutsch
* @var string
*/
private $description;
/**
* Constructor
* @param StdClass $obj
* @param string $description
*/
public function __construct( $obj, $description ) {
if ( is_object( $obj ) ) {
$this->obj = $obj;
$this->language = (string) get_blog_option(
$this->obj->userblog_id, 'WPLANG'
);
}
$this->description = (string) $description;
}
/**
* Get a member of the StdClass-object by name
*
* The method return <em>null</em> if the requested member does not exists.
* @param string $key
* @return mixed|null
*/
final public function __get( $key ) {
return( isset( $this->obj->$key ) ? $this->obj->$key : null );
}
/**
* Get the description stored in this object
*
* The method returns the stored language if the description is empty.
* @return string
*/
public function get_description() {
return(
empty( $this->description ) ?
$this->get_language() :
$this->description
);
}
/**
* Get the language stored in this object
*
* This method returns the string 'us' if there is an empty value in language.
* @return string
*/
public function get_language() {
return( empty( $this->language ) ? 'us' : $this->language );
}
/**
* Get the alpha2-part of the language-code
*
* This method returns the string 'en' if the language-code contains just 'us'.
* @return string
*/
public function get_alpha2() {
$alpha2 = substr( $this->get_language(), 0, 2 );
return( 'us' == $alpha2 ? 'en' : $alpha2 );
}
/**
* Sort objects helper
* @param string $a
* @param string $b
* return int
*/
public static function _cmp( $a, $b ) {
if ( $a == $b ) {
return 0;
}
return( $a < $b ? (-1) : 1 );
}
/**
* Sort objects by language
* @param MslsBlog $a
* @param MslsBlog $b
* return int
*/
public static function language( MslsBlog $a, MslsBlog $b ) {
return( self::_cmp( $a->get_language(), $b->get_language() ) );
}
/**
* Sort objects by description
* @param MslsBlog $a
* @param MslsBlog $b
* return int
*/
public static function description( MslsBlog $a, MslsBlog $b ) {
return( self::_cmp( $a->get_description(), $b->get_description() ) );
}
}