Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rajulKhabir.mondal committed Jul 2, 2018
1 parent 2d3986f commit d4a14fa
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 132 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ Stay Alive: wordpress plugin to check logged in user's status

# Short Code

*coming soon!*
[sa_online_users]

# Download
[2.1.0](https://github.com/razzul/stay-alive/releases) latest version of **stay-alive**
[2.2.0](https://github.com/razzul/stay-alive/releases) latest version of **stay-alive**

# How to use it
*Update pusher details and callback function from admin [plugin page](http://localhost/wordpress-talk/wp-admin/options-general.php?page=stay-alive-admin)*

Apply the shortcode in your page or enable the widget

At any point of time in you application call javascript funciton
```HTML
Expand Down
36 changes: 0 additions & 36 deletions auth/pusher.php

This file was deleted.

74 changes: 74 additions & 0 deletions stay-alive-widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

class StayAliveWidget extends WP_Widget {

// constructor
function StayAliveWidget() {
// Give widget name here
parent::WP_Widget(false, $name = __('Onlin Users', 'wp_widget_plugin') );

}

function form($instance) {
// Check values
if( $instance) {
$title = esc_attr($instance['title']);
$textarea = $instance['textarea'];
} else {
$title = '';
$textarea = '';
}
?>

<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('textarea'); ?>"><?php _e('Description:', 'wp_widget_plugin'); ?></label>
<textarea class="widefat" id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>" rows="7" cols="20" ><?php echo $textarea; ?></textarea>
</p>
<?php
}

function update($new_instance, $old_instance) {
$instance = $old_instance;
// Fields
$instance['title'] = strip_tags($new_instance['title']);
$instance['textarea'] = strip_tags($new_instance['textarea']);
return $instance;
}

// display widget
function widget($args, $instance) {
extract( $args );

// these are the widget options
$title = apply_filters('widget_title', $instance['title']);
$textarea = $instance['textarea'];
echo $before_widget;

// Display the widget
echo '<div class="widget-text wp_widget_plugin_box" style="width:269px; padding:5px 9px 20px 5px; border: 1px solid rgb(231, 15, 52); background: pink; border-radius: 5px; margin: 10px 0 25px 0;">';
echo '<div class="widget-title" style="width: 90%; height:30px; margin-left:3%; ">';

// Check if title is set
if ( $title ) {
echo $before_title . $title . $after_title ;
}
echo '</div>';

// Check if textarea is set
echo '<div class="widget-textarea" style="width: 90%; margin-left:3%; padding:8px; background-color: white; border-radius: 3px; min-height: 70px;">';
if( $textarea ) {
echo '<p class="wp_widget_plugin_textarea" style="font-size:15px;">'.$textarea.'</p>';
}
echo '</div>';
echo '</div>';
echo $after_widget;
}

}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("StayAliveWidget");'));
176 changes: 82 additions & 94 deletions stay-alive.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Stay Alive
Plugin URI: https://github.com/razzul/stayalive
description: Stay Alive: wordpress plugin to check logged in user's status
Version: 2.1.0
Version: 1.0
Author: razzul
Author URI: https://github.com/razzul
License: MIT
Expand All @@ -13,6 +13,8 @@
exit; // Exit if accessed directly
}

include __DIR__ . '/stay-alive-widget.php';

/**
*
*/
Expand All @@ -37,6 +39,16 @@ public function __construct()
add_action('wp_logout', array($this, 'user_logout'));
add_action('wp_login', array($this, 'user_in'));
add_action('wp_ajax_stay_alive_auth', array($this, 'stay_alive_auth'));
add_shortcode('sa_online_users', array($this, 'stay_alive_shortcode'));
}

public function stay_alive_shortcode()
{
?>
<div class="stay_alive">
<ul class="stay_alive_users"></ul>
</div>
<?php
}

public function stay_alive_auth()
Expand Down Expand Up @@ -90,77 +102,76 @@ public function stay_alive_checker()
function test_stay_alive(members) {
console.log(members);
}
console.log("StayAlive: loaded");
var StayAlive = function() {
this.pusher = null;
this.channel = null;
this.current_user_id = "' . $current_user_id . '"
this.channel_name = "' .$channel_name . '"
this.event_name = "' . $event_name . '"
this.status = false
this.credentials = function() {
return ' . json_encode($options) . '
}
this.subscribe = function() {
this.pusher = new Pusher(this.credentials().pusher_key, { cluster: this.credentials().pusher_cluster , authEndpoint: "'. site_url() .'/wp-admin/admin-ajax.php?action=stay_alive_auth",});
this.channel = this.pusher.subscribe(this.channel_name);
}
this.unsubscribe = function() {
this.pusher.unsubscribe(this.channel_name);
}
this.count = function() {
return this.channel.members.count
}
this.me = function() {
return this.channel.members.me
}
this.users = function() {
return this.channel.members.members
jQuery(document).ready(function(){
console.log("StayAlive: loaded");
var StayAlive = function() {
this.pusher = null;
this.channel = null;
this.current_user_id = "' . $current_user_id . '"
this.channel_name = "' .$channel_name . '"
this.event_name = "' . $event_name . '"
this.status = false
this.credentials = function() {
return ' . json_encode($options) . '
}
this.subscribe = function() {
this.pusher = new Pusher(this.credentials().pusher_key, { cluster: this.credentials().pusher_cluster , authEndpoint: "'. site_url() .'/wp-admin/admin-ajax.php?action=stay_alive_auth",});
this.channel = this.pusher.subscribe(this.channel_name);
}
this.unsubscribe = function() {
this.pusher.unsubscribe(this.channel_name);
}
this.count = function() {
return this.channel.members.count
}
this.me = function() {
return this.channel.members.me
}
this.users = function() {
return this.channel.members.members
}
this.online = function() {
stay_alive.subscribe()
this.channel.bind("pusher:subscription_succeeded", function(members) {
jQuery("ul.stay_alive_users").empty()
for(var i = 1; i <= members.count; i++) {
jQuery("ul.stay_alive_users").append("<li>"+ members.members[i].name +"</li>")
}
});
this.channel.bind("pusher:member_added", function(member) {
members = stay_alive.users()
jQuery("ul.stay_alive_users").empty()
for(var i = 1; i <= stay_alive.count(); i++) {
jQuery("ul.stay_alive_users").append("<li>"+ members[i].name +"</li>")
}
});
this.channel.bind("pusher:member_removed", function(member) {
members = stay_alive.users()
jQuery("ul.stay_alive_users").empty()
for(var i = 1; i <= stay_alive.count(); i++) {
jQuery("ul.stay_alive_users").append("<li>"+ members[i].name +"</li>")
}
});
}
}
this.online = function(callback = "test_stay_alive") {
stay_alive.subscribe()
this.channel.bind("pusher:subscription_succeeded", function(members) {
if(callback == "") {
test_stay_alive(members.members)
} else {
callback(members.members)
}
});
this.channel.bind("pusher:member_added", function(member) {
members = stay_alive.users()
if(callback == "") {
test_stay_alive(members)
} else {
callback(members)
}
});
this.channel.bind("pusher:member_removed", function(member) {
members = stay_alive.users()
if(callback == "") {
test_stay_alive(members)
} else {
callback(members)
}
});
}
}
var stay_alive = new StayAlive()
stay_alive.online('. $stay_alive_trigger .')
var stay_alive = new StayAlive()
stay_alive.online()
})
</script>
';
}
Expand Down Expand Up @@ -264,14 +275,6 @@ public function page_init()
'stay-alive-admin',
'setting_section_id'
);

add_settings_field(
'stay_alive_trigger',
'Callback Function (js)',
array($this, 'stay_alive_trigger_callback'),
'stay-alive-admin',
'setting_section_id'
);
}

/**
Expand All @@ -298,10 +301,6 @@ public function sanitize($input)
$new_input['pusher_cluster'] = sanitize_text_field($input['pusher_cluster']);
}

if (isset($input['stay_alive_trigger'])) {
$new_input['stay_alive_trigger'] = sanitize_text_field($input['stay_alive_trigger']);
}

return $new_input;
}

Expand Down Expand Up @@ -357,17 +356,6 @@ public function pusher_cluster_callback()
);
}

/**
* Get the settings option array and print one of its values
*/
public function stay_alive_trigger_callback()
{
printf(
'<input type="text" id="stay_alive_trigger" name="stay_alive_credentials[stay_alive_trigger]" value="%s" /><br><span>Default value: test_stay_alive</span><br><b>No need to user parenthesis symbol "()"</b>',
isset($this->options['stay_alive_trigger']) ? esc_attr($this->options['stay_alive_trigger']) : ''
);
}

}

$stay_alive_page = new StayAlive();
$stay_alive_page = new StayAlive();

0 comments on commit d4a14fa

Please sign in to comment.