Example #1
0
 /**
  * Detailed Activity Log
  *
  * @todo Add geolocation service.
  * @todo Add caching for host resolution.
  */
 static function get_detailed_activity_log($args = '')
 {
     global $wpdb, $wp_crm;
     $args = wp_parse_args($args, array('object_type' => 'user', 'hide_empty' => false, 'order_by' => 'time', 'start' => '0', 'import_count' => 500, 'get_count' => 'false', 'filter_types' => array(array('attribute' => 'detailed_log', 'other' => 2, 'hidden' => 'false'))));
     $activity_log = WP_CRM_F::get_events($args);
     $_resolved = array();
     $_locations = get_transient('_wpc_geolocation');
     if (!$_locations) {
         $_update_cache = true;
     }
     foreach ((array) $activity_log as $count => $entry) {
         $activity_log[$count]->display_name = get_userdata($entry->object_id)->display_name;
         $activity_log[$count]->edit_url = admin_url('admin.php?page=wp_crm_add_new&user_id=' . $entry->object_id);
         $activity_log[$count]->time_stamp = strtotime($entry->time);
         $activity_log[$count]->date = date(get_option('date_format', strtotime($entry->time)));
         $activity_log[$count]->time_ago = human_time_diff(strtotime($entry->time)) . __(' ago.', 'wpp');
         switch (true) {
             case $entry->attribute == 'detailed_log' && $entry->action == 'login':
                 $activity_log[$count]->text = sprintf(__('Logged in from %1s.', 'wpp'), $entry->value);
                 if (function_exists('gethostbyaddr')) {
                     $activity_log[$count]->host_name = $_resolved[$entry->value] ? $_resolved[$entry->value] : ($_resolved[$entry->value] = @gethostbyaddr($entry->value));
                 }
                 if ($entry->value) {
                     $activity_log[$count]->location = $_locations[$entry->value] ? $_locations[$entry->value] : ($_locations[$entry->value] = WP_CRM_F::get_service('geolocation', '', $entry->value, array('json')));
                 }
                 break;
             case $entry->attribute == 'detailed_log' && $entry->action == 'logout':
                 $activity_log[$count]->text = sprintf(__('Logged out from %1s.', 'wpp'), $entry->value);
                 if (function_exists('gethostbyaddr')) {
                     $activity_log[$count]->host_name = $_resolved[$entry->value] ? $_resolved[$entry->value] : ($_resolved[$entry->value] = @gethostbyaddr($entry->value));
                 }
                 if ($entry->value) {
                     $activity_log[$count]->location = $_locations[$entry->value] ? $_locations[$entry->value] : ($_locations[$entry->value] = WP_CRM_F::get_service('geolocation', '', $entry->value, array('json')));
                 }
                 break;
         }
     }
     if ($_update_cache && $_locations) {
         set_transient('_wpc_geolocation', $_locations, 3600);
     }
     return $activity_log;
 }