Skip to content
Snippets Groups Projects
Commit c841ed7b authored by void's avatar void
Browse files

Statusanzeige als Widget implementiert

parent a0d7efc0
No related branches found
No related tags found
No related merge requests found
...@@ -17,13 +17,6 @@ ...@@ -17,13 +17,6 @@
- "/srv/wordpress/data/" - "/srv/wordpress/data/"
- "/srv/wordpress/db/" - "/srv/wordpress/db/"
- name: create config files
template:
src: "{{ item }}"
dest: "/srv/wordpress/config/{{ item }}"
with_items:
- uploads.ini
- name: create config file - name: create config file
template: template:
src: "{{ item }}" src: "{{ item }}"
...@@ -31,8 +24,10 @@ ...@@ -31,8 +24,10 @@
with_items: with_items:
- Dockerfile - Dockerfile
- docker-compose.yml - docker-compose.yml
- config/uploads.ini
- data/wp-content/plugins/wz-status/wz-status.php
# - name: start wordpress docker - name: start wordpress docker
# docker_service: docker_compose:
# project_src: /srv/wordpress/ project_src: /srv/wordpress/
# state: present state: present
<?php
/*
Plugin Name: WZ Status
Plugin URI: http://www.warpzone.ms
Description: This plugin adds a custom widget.
Version: 1.0
Author: Christian <void> Elberfeld
Author URI: http://www.warpzone.ms
License: GPL2
Original Source: https://github.com/wpexplorer/my-widget-plugin
*/
// The widget class
class WZ_Status_Widget extends WP_Widget {
// Main constructor
public function __construct() {
parent::__construct(
'wz_status_widget',
__( 'WZ Status Widget', 'text_domain' ),
array(
'customize_selective_refresh' => true,
)
);
}
// The widget form (for the backend )
public function form( $instance ) {
// Set widget defaults
$defaults = array(
'title' => '',
'api_url' => '',
);
// Parse current settings with defaults
extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>
<?php // Widget Title ?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Widget Title', 'text_domain' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php // Api Url ?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'api_url' ) ); ?>"><?php _e( 'Api Url:', 'api_url' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'api_url' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'api_url' ) ); ?>" type="text" value="<?php echo esc_attr( $text ); ?>" />
</p>
<?php }
// Update widget settings
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
$instance['api_url'] = isset( $new_instance['api_url'] ) ? wp_strip_all_tags( $new_instance['api_url'] ) : '';
return $instance;
}
// Display the widget
public function widget( $args, $instance ) {
extract( $args );
// Check the widget options
$title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
$api_url = isset( $instance['api_url'] ) ? $instance['api_url'] : '';
$zone_status = "UNBEKANNT";
$zone_status_text = "Unbekannt";
$zone_status_color = "#000000";
// WordPress core before_widget hook (always include )
echo $before_widget;
// Display the widget
echo '<div class="widget-text wp_widget_plugin_box">';
// Display widget title if defined
if ( $title ) {
echo $before_title . $title . $after_title;
}
// Zone Status abrufen
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.warpzone.ms/statuswidget",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$zone_status = $err;
} else {
$responseObj = json_decode($response,true);
$zone_status = $responseObj['zone_door_status'];
if ($zone_status == "OPEN") {
$zone_status_text = "Offen";
$zone_status_color = "#00cc00";
}
if ($zone_status == "CLOSED") {
$zone_status_text = "Geschlossen";
$zone_status_color = "#cc0000";
}
}
// Anzeige Status im Widget
echo "<span style='font-weight: bold; color:" . $zone_status_color . ";'>" . $zone_status_text . "</span>";
// Status mit in die Menueleiste fuer Mobilgeraete
echo "<script type='text/javascript'>jQuery(document).ready(function() { jQuery('#mainnav-toggle').text('MENU | Status: " . $zone_status_text . "'); });</script>";
echo '</div>';
// WordPress core after_widget hook (always include )
echo $after_widget;
}
}
// Register the widget
function my_register_wz_status_widget() {
register_widget( 'WZ_Status_Widget' );
}
add_action( 'widgets_init', 'my_register_wz_status_widget' );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment