forked from lloc/Multisite-Language-Switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultisiteLanguageSwitcher.php
163 lines (144 loc) · 5.48 KB
/
MultisiteLanguageSwitcher.php
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/*
Plugin Name: Multisite Language Switcher
Plugin URI: http://lloc.de/msls
Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation.
Version: 0.9.7
Author: Dennis Ploetner
Author URI: http://lloc.de/
*/
/*
Copyright 2011 Dennis Ploetner (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( !class_exists( 'MslsAutoloader' ) ) {
if ( !defined( 'MSLS_PLUGIN_VERSION' ) )
define( 'MSLS_PLUGIN_VERSION', '0.9.7' );
if ( !defined( 'MSLS_PLUGIN_PATH' ) )
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
if ( !defined( 'MSLS_PLUGIN__FILE__' ) )
define( 'MSLS_PLUGIN__FILE__', __FILE__ );
/**
* The Autoloader does all the magic when it comes to include a file
* @package Msls
*/
class MslsAutoloader {
/**
* Static loader method
* @param string $cls
*/
public static function load( $cls ) {
if ( 'Msls' == substr( $cls, 0, 4 ) )
require_once dirname( __FILE__ ) . '/includes/' . $cls . '.php';
}
}
/**
* Interface for classes which are to register in the MslsRegistry-instance
*
* get_called_class is just avalable in php >= 5.3 so I defined an interface here
* @package Msls
*/
interface IMslsRegistryInstance {
/**
* @return object
*/
public static function instance();
}
/**
* The autoload-stack could be inactive so the function will return false
*/
if ( in_array( '__autoload', (array) spl_autoload_functions() ) )
spl_autoload_register( '__autoload' );
spl_autoload_register( array( 'MslsAutoloader', 'load' ) );
register_activation_hook( __FILE__, array( 'MslsPlugin', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'MslsPlugin', 'deactivate' ) );
register_uninstall_hook( __FILE__, array( 'MslsPlugin', 'uninstall' ) );
add_action( 'init', array( 'MslsPlugin', 'init_i18n_support' ) );
add_action( 'widgets_init', array( 'MslsPlugin', 'init_widget' ) );
if ( is_admin() ) {
add_action( 'admin_menu', array( 'MslsAdmin', 'init' ) );
add_action( 'load-post.php', array( 'MslsMetaBox', 'init' ) );
add_action( 'load-post-new.php', array( 'MslsMetaBox', 'init' ) );
add_action( 'load-edit.php', array( 'MslsCustomColumn', 'init' ) );
add_action( 'load-edit-tags.php', array( 'MslsPostTag', 'init' ) );
add_action( 'load-edit-tags.php', array( 'MslsCustomColumnTaxonomy', 'init' ) );
if ( !empty( $_POST['action'] ) ) {
if ( 'add-tag' == $_POST['action'] )
add_action( 'admin_init', array( 'MslsPostTag', 'init' ) );
elseif ( 'inline-save' == $_POST['action'] )
add_action( 'admin_init', array( 'MslsCustomColumn', 'init' ) );
elseif ( 'inline-save-tax' == $_POST['action'] )
add_action( 'admin_init', array( 'MslsCustomColumnTaxonomy', 'init' ) );
}
}
/**
* Filter for the_content()
*
* @package Msls
* @uses MslsOptions
* @uses MslsOutput
* @param string $content
* @return string
*/
function msls_content_filter( $content ) {
if ( !is_front_page() && is_singular() ) {
$options = MslsOptions::instance();
if ( $options->is_content_filter() ) {
$obj = new MslsOutput();
$links = $obj->get( 1, true, true );
if ( !empty( $links ) ) {
if ( count( $links ) > 1 ) {
$last = array_pop( $links );
$links = sprintf(
__( '%s and %s', 'msls' ),
implode( ', ', $links ),
$last
);
} else {
$links = $links[0];
}
$content .= '<p id="msls">' .
sprintf(
__( 'This post is also available in %s.', 'msls' ),
$links
) .
'</p>';
}
}
}
return $content;
}
add_filter( 'the_content', 'msls_content_filter' );
/**
* Get the output for using the links to the translations in your code
*
* @return string
* @package Msls
* @see the_msls()
*/
function get_the_msls() {
$obj = new MslsOutput();
return( sprintf( '%s', $obj ) );
}
/**
* Output the links to the translations in your template
*
* You can call of this function directly like that
* <code>if ( function_exists ( 'the_msls' ) ) the_msls();</code>
*
* @package Msls
* @uses get_the_msls()
*/
function the_msls() {
echo get_the_msls();
}
}