singleton.
*
* @since 2.0.9.1
*/
private function __construct() {
if ( ! session_id() ) {
session_start();
}
if ( isset( $_GET['cs-explain'] ) ) {
self::set_explain( $_GET['cs-explain'] );
}
if ( is_admin() ) {
add_action(
'cs_widget_header',
array( $this, 'widget_header' )
);
add_action(
'cs_ajax_request',
array( $this, 'handle_ajax' )
);
} else {
if ( self::do_explain() ) {
add_action(
'cs_explain',
array( $this, 'add_info' ),
10, 2
);
add_action(
'wp_footer',
array( $this, 'show_infos' )
);
add_action(
'dynamic_sidebar_before',
array( $this, 'before_sidebar' ),
0, 2
);
add_action(
'dynamic_sidebar_after',
array( $this, 'after_sidebar' ),
0, 2
);
}
}
}
/**
* Called by action 'cs_widget_header'. Output the export/import button in
* the widget header.
*
* @since 2.0.9.1
*/
public function widget_header() {
/*
$state = self::do_explain() ? 'on' : 'off';
?>
'ERR',
);
switch ( $ajax_action ) {
case 'explain':
$handle_it = true;
break;
}
if ( ! $handle_it ) {
return false;
}
$state = @$_POST['state'];
switch ( $ajax_action ) {
case 'explain':
self::set_explain( $state );
$req->status = 'OK';
$req->state = self::do_explain() ? 'on' : 'off';
break;
}
self::json_response( $req );
}
/**
* Returns true if the "explain mode" is enabled.
* Explain mode will display additional information in the front-end of the
* website on why which sidebar/widget is displayed.
* This is a per-user option (stored in current session)
*
* @since 2.0.9.1
* @return boolean
*/
public static function do_explain() {
return
isset( $_SESSION['cs-explain'] )
&& is_string( $_SESSION['cs-explain'] )
&& 'on' == $_SESSION['cs-explain'];
}
/**
* Sets the explain state
*
* @since 2.0.9.1
* @param string $state [on|off]
*/
public static function set_explain( $state ) {
if ( 'on' != $state ) {
$state = 'off';
}
$_SESSION['cs-explain'] = $state;
}
/**
* Adds an info to the explanation output.
*
* @since 2.0.9.1
*/
public function add_info( $info, $new_item = false ) {
if ( $new_item ) {
$this->infos[] = $info;
} else {
$this->infos[ count( $this->infos ) - 1 ] .= '
' . $info;
}
}
/**
* Outputs the collected information to the webpage.
*
* @since 2.0.9.1
*/
public function show_infos() {
#global $wp_registered_sidebars;
#var_dump( $wp_registered_sidebars );
?>