diff --git a/webserver/docker_wordpress/tasks/main.yml b/webserver/docker_wordpress/tasks/main.yml index 7ec0b667928df40505c0451c8f35bdc5b611acd8..6e69e0641df98b3452eef4e7ea356b92d8d8c4aa 100644 --- a/webserver/docker_wordpress/tasks/main.yml +++ b/webserver/docker_wordpress/tasks/main.yml @@ -17,13 +17,6 @@ - "/srv/wordpress/data/" - "/srv/wordpress/db/" -- name: create config files - template: - src: "{{ item }}" - dest: "/srv/wordpress/config/{{ item }}" - with_items: - - uploads.ini - - name: create config file template: src: "{{ item }}" @@ -31,8 +24,10 @@ with_items: - Dockerfile - docker-compose.yml + - config/uploads.ini + - data/wp-content/plugins/wz-status/wz-status.php -# - name: start wordpress docker -# docker_service: -# project_src: /srv/wordpress/ -# state: present +- name: start wordpress docker + docker_compose: + project_src: /srv/wordpress/ + state: present diff --git a/webserver/docker_wordpress/templates/uploads.ini b/webserver/docker_wordpress/templates/config/uploads.ini similarity index 100% rename from webserver/docker_wordpress/templates/uploads.ini rename to webserver/docker_wordpress/templates/config/uploads.ini diff --git a/webserver/docker_wordpress/templates/data/wp-content/plugins/wz-status/wz-status.php b/webserver/docker_wordpress/templates/data/wp-content/plugins/wz-status/wz-status.php new file mode 100644 index 0000000000000000000000000000000000000000..36b3bf0a09affb3d2a6345d314291b8d84c4659d --- /dev/null +++ b/webserver/docker_wordpress/templates/data/wp-content/plugins/wz-status/wz-status.php @@ -0,0 +1,152 @@ +<?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' ); +