Changeset 1826576
- Timestamp:
- 02/21/2018 11:46:46 PM (8 years ago)
- Location:
- traffic-lights/trunk
- Files:
-
- 4 edited
-
draw-traffic-lights.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
traffic-lights-widget.php (modified) (5 diffs)
-
traffic-lights.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
traffic-lights/trunk/draw-traffic-lights.php
r1544877 r1826576 1 1 <?php 2 2 3 4 5 if 6 ( function_exists('user_begins_to_work')) 3 if (function_exists('user_begins_to_work')) 7 4 { 8 $all_users=get_users(); 9 $somebody_is_green=false; 10 $green=false; 11 foreach 12 ($all_users as $user) 5 $all_users = get_users(); 6 $somebody_is_green = false; 7 $green = false; 8 foreach($all_users as $user) 13 9 { 14 $the_user_id=$user->data->ID; 15 $in_office=get_user_meta($the_user_id, "in_office", true); 16 $in_pause=get_user_meta($the_user_id, "in_pause", true); 17 18 if ($in_office=="yes" && $in_pause=="no") 10 $the_user_id = $user->data->ID; 11 $in_office = get_user_meta($the_user_id, "in_office", true); 12 $in_pause = get_user_meta($the_user_id, "in_pause", true); 13 if ($in_office == "yes" && $in_pause == "no") 19 14 { 20 15 update_option('ampel', 'gruen'); 21 $green =true;16 $green = true; 22 17 break; 23 }else if 24 ($in_pause=="yes" && $green==false) 25 { 26 update_option('ampel', 'gelb'); 27 break; 28 29 }else 18 } 19 else 20 if ($in_pause == "yes" && $green == false) 21 { 22 update_option('ampel', 'gelb'); 23 break; 24 } 25 else 30 26 { 31 27 update_option('ampel', 'rot'); 28 } 29 } 30 } 32 31 33 }} 32 // Eine Funktion um eine Ampel anzuzeigen 34 33 35 }36 // Eine Funktion um eine Ampel anzuzeigen37 34 function draw_traffic_light() 38 35 { 39 36 echo "<div style=\"line-height:0px;padding:0;text-decoration:none;\">"; 40 $ampel_url=plugins_url( 'bilder/' , __FILE__ ); 41 42 if 43 (isset($_GET['ampel']) && current_user_can( 'change_traffic_light',0 ) ) 37 $ampel_url = plugins_url('bilder/', __FILE__); 38 if (isset($_GET['ampel']) && current_user_can('change_traffic_light', 0)) 44 39 { 45 40 update_option('ampel', $_GET['ampel']); 46 41 } 47 $farbe=get_option('ampel');48 42 49 if ($farbe=="rot") 43 $farbe = get_option('ampel'); 44 if ($farbe == "rot") 50 45 { 51 echo "<img src=\"".$ampel_url."red.png\" /><br />"; 52 }else 46 echo "<img src=\"" . $ampel_url . "red.png\" /><br />"; 47 } 48 else 53 49 { 54 if ( current_user_can( 'change_traffic_light',0 ) ) 55 {echo "<a href=\"?ampel=rot\">"; 56 }else 57 {} 58 echo "<img src=\"".$ampel_url."red-off.png\" />"; 59 if ( current_user_can( 'change_traffic_light',0 ) ) 60 {echo "</a>"; 50 if (current_user_can('change_traffic_light', 0)) 51 { 52 echo "<a href=\"?ampel=rot\">"; 61 53 } 54 else 55 { 56 } 57 58 echo "<img src=\"" . $ampel_url . "red-off.png\" />"; 59 if (current_user_can('change_traffic_light', 0)) 60 { 61 echo "</a>"; 62 } 63 62 64 echo "<br />"; 63 65 } 64 if ($farbe=="gelb") 66 67 if ($farbe == "gelb") 65 68 { 66 echo "<img src=\"".$ampel_url."yellow.png\" /><br />"; 67 }else 69 echo "<img src=\"" . $ampel_url . "yellow.png\" /><br />"; 70 } 71 else 68 72 { 69 if ( current_user_can( 'change_traffic_light',0 ) ) 70 {echo "<a href=\"?ampel=gelb\">"; 73 if (current_user_can('change_traffic_light', 0)) 74 { 75 echo "<a href=\"?ampel=gelb\">"; 71 76 } 72 echo "<img src=\"".$ampel_url."yellow-off.png\" />"; 73 if ( current_user_can( 'change_traffic_light',0 ) ) 74 {echo "</a>"; 77 78 echo "<img src=\"" . $ampel_url . "yellow-off.png\" />"; 79 if (current_user_can('change_traffic_light', 0)) 80 { 81 echo "</a>"; 75 82 } 83 76 84 echo "<br />"; 77 85 } 78 if ($farbe=="gruen") 86 87 if ($farbe == "gruen") 79 88 { 80 echo "<img src=\"".$ampel_url."green.png\" /><br />"; 81 }else 89 echo "<img src=\"" . $ampel_url . "green.png\" /><br />"; 90 } 91 else 82 92 { 83 if ( current_user_can( 'change_traffic_light',0 ) ) 84 {echo "<a href=\"?ampel=gruen\">"; 93 if (current_user_can('change_traffic_light', 0)) 94 { 95 echo "<a href=\"?ampel=gruen\">"; 85 96 } 86 echo "<img src=\"".$ampel_url."green-off.png\" />"; 87 if ( current_user_can( 'change_traffic_light',0 ) ) 88 {echo "</a>"; 97 98 echo "<img src=\"" . $ampel_url . "green-off.png\" />"; 99 if (current_user_can('change_traffic_light', 0)) 100 { 101 echo "</a>"; 89 102 } 103 90 104 echo "<br />"; 91 105 } 106 92 107 echo "</div>"; 93 94 108 } 95 109 -
traffic-lights/trunk/readme.txt
r1544880 r1826576 4 4 Tags: traffic,lights,status 5 5 Requires at least: 3.0 6 Tested up to: 4.77 Stable tag: 1.0 6 Tested up to: 5.0 7 Stable tag: 1.01 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 As traffic light function for projects every logged in user can choose between red, amber and green. 18 18 19 You have it as dashboard widget, as sidebar widget and shortcode [trafficlights] .19 You have it as dashboard widget, as sidebar widget and shortcode [trafficlights] or [traffic-lights]. 20 20 21 21 This Version can be connected with "HRM Work Tracking" and is showing Green for somebody is present, yellow somebody is there but in pause and red nobody is there. -
traffic-lights/trunk/traffic-lights-widget.php
r1544877 r1826576 1 1 <?php 2 class traffic_light_Widget extends WP_Widget { 2 class traffic_light_Widget extends WP_Widget 3 4 { 3 5 /** 4 6 * Register widget with WordPress. … … 6 8 function __construct() 7 9 { 8 parent::__construct( 9 'traffic_light_Widget', // Base ID 10 __('Traffic Lights', 'text_domain'), // Name 11 array( 'description' => __( 'A traffic Light Widget', 'text_domain' ), ) // Args 10 parent::__construct('traffic_light_Widget', // Base ID 11 __('Traffic Lights', 'text_domain') , // Name 12 array( 13 'description' => __('A traffic Light Widget', 'text_domain') , 14 ) // Args 12 15 ); 13 16 } … … 21 24 * @param array $instance Saved values from database. 22 25 */ 23 public function widget( $args, $instance)26 public function widget($args, $instance) 24 27 { 25 $title = apply_filters( 'widget_title', $instance['title'] ); 26 28 if (! empty( $instance['title'] ) ) 29 { 30 $title = apply_filters('widget_title', $instance['title'] ); 31 } 32 27 33 echo $args['before_widget']; 28 if ( ! empty( $title ) ) 29 echo $args['before_title'] . $title . $args['after_title']; 34 if (!empty($title)) echo $args['before_title'] . $title . $args['after_title']; 30 35 draw_traffic_light(); 31 36 echo $args['after_widget']; … … 39 44 * @param array $instance Previously saved values from database. 40 45 */ 41 public function form( $instance)46 public function form($instance) 42 47 { 43 if ( isset( $instance[ 'title' ] ))48 if (isset($instance['title'])) 44 49 { 45 $title = $instance[ 'title'];50 $title = $instance['title']; 46 51 } 47 52 else 48 53 { 49 $title = __( 'New title', 'text_domain');54 $title = __('New title', 'text_domain'); 50 55 } 56 51 57 ?> 52 58 <p> 53 <label for="<?php echo $this->get_field_id( 'title' ); 54 ?>"><?php _e( 'Title:' ); 55 ?></label> 56 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); 57 ?>" name="<?php echo $this->get_field_name( 'title' ); 58 ?>" type="text" value="<?php echo esc_attr( $title ); 59 ?>" /> 59 <label for="<?php 60 echo $this->get_field_id('title'); 61 ?>"><?php 62 _e('Title:'); 63 ?></label> 64 <input class="widefat" id="<?php 65 echo $this->get_field_id('title'); 66 ?>" name="<?php 67 echo $this->get_field_name('title'); 68 ?>" type="text" value="<?php 69 echo esc_attr($title); 70 ?>" /> 60 71 </p> 61 72 <?php … … 72 83 * @return array Updated safe values to be saved. 73 84 */ 74 public function update( $new_instance, $old_instance)85 public function update($new_instance, $old_instance) 75 86 { 76 87 $instance = array(); 77 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; 78 88 $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; 79 89 return $instance; 80 90 } 91 } // class traffic_light_Widget 81 92 82 } // class traffic_light_Widget83 93 ?> -
traffic-lights/trunk/traffic-lights.php
r1544880 r1826576 4 4 Plugin URI: http://www.wp-plugin-dev.com 5 5 Description: A simple Traffic Light to show some state for visitor 6 Version: 1.0 6 Version: 1.01 7 7 Author: wp-plugin-dev.com 8 Author URI: http ://www.wp-plugin-dev.com8 Author URI: https://www.wp-plugin-dev.com 9 9 License: GPLv2 or later 10 10 Graphic from http://www.openclipart.org/ … … 12 12 Jedes WordPress Plugin hat die oben gemachten Angaben 13 13 */ 14 14 15 // um das Haupt Plugin File nicht so sehr mit Code voll zu machen 15 16 // rufen wir nur die anderen Files auf. 16 17 // Das Dokument was die Ampel malt 18 17 19 include 'draw-traffic-lights.php'; 20 18 21 include 'traffic-lights-widget.php'; 19 22 20 register_activation_hook( __FILE__, 'add_traffic_lights_caps');23 register_activation_hook(__FILE__, 'add_traffic_lights_caps'); 21 24 22 function add_traffic_lights_caps() { 23 24 $roles = array ('subscriber','author','editor','contributor','administrator'); 25 26 foreach ($roles as $role) 27 { 28 $role = get_role( $role ); 29 $role->add_cap( 'change_traffic_light' ); 25 function add_traffic_lights_caps() 26 { 27 $roles = array( 28 'subscriber', 29 'author', 30 'editor', 31 'contributor', 32 'administrator' 33 ); 34 foreach($roles as $role) 35 { 36 $role = get_role($role); 37 $role->add_cap('change_traffic_light'); 30 38 } 31 39 } 32 40 41 // register traffic_light_Widget widget 33 42 34 // register traffic_light_Widget widget35 43 function register_traffic_light_Widget() 36 44 { 37 register_widget( 'traffic_light_Widget');45 register_widget('traffic_light_Widget'); 38 46 } 39 47 40 add_action( 'widgets_init', 'register_traffic_light_Widget');48 add_action('widgets_init', 'register_traffic_light_Widget'); 41 49 42 50 // Function that outputs the contents of the dashboard widget 51 43 52 function dashboard_widget_function_traffic_light() 44 53 { … … 47 56 48 57 // Function used in the action hook 58 49 59 function add_dashboard_widgets_tl() 50 60 { … … 53 63 54 64 // Register the new dashboard widget with the 'wp_dashboard_setup' action 55 add_action('wp_dashboard_setup', 'add_dashboard_widgets_tl' );56 65 66 add_action('wp_dashboard_setup', 'add_dashboard_widgets_tl'); 57 67 add_shortcode("trafficlights", "trafficlight_shorty"); 68 add_shortcode("traffic-lights", "trafficlight_shorty"); 58 69 59 70 function trafficlight_shorty()
Note: See TracChangeset
for help on using the changeset viewer.