widgetName = JText::translate('VBO_W_VISITCOUNT_TITLE'); $this->widgetDescr = JText::translate('VBO_W_VISITCOUNT_DESCR'); $this->widgetId = basename(__FILE__, '.php'); /** * Define widget and icon and style name. * * @since 1.15.0 (J) - 1.5.0 (WP) */ $this->widgetIcon = ''; $this->widgetStyleName = 'blue'; } /** * Custom method for this widget only to count the visitors. * The method is called by the admin controller through an AJAX request. * The visibility should be public, it should not exit the process, and * any content sent to output will be returned to the AJAX response. */ public function countVisitors() { // load the tracker object without starting to track any data VikBooking::getTracker(true); // total unique and active visitors today $today_from = date('Y-m-d') . ' 00:00:00'; $today_to = date('Y-m-d') . ' 23:59:59'; $tot_today = VikBookingTracker::countTrackedRecords($today_from, $today_to); // total unique and active visitors this month until the end of today $month_from = date('Y-m') . '-01 00:00:00'; $tot_month = VikBookingTracker::countTrackedRecords($month_from, $today_to); // total unique and active visitors last month until the end of today's month day $now = getdate(); $last_month_from = date('Y-m-d H:i:s', mktime(0, 0, 0, ($now['mon'] - 1), 1, $now['year'])); $last_month_to = date('Y-m-d H:i:s', mktime(23, 59, 59, ($now['mon'] - 1), $now['mday'], $now['year'])); $tot_last_month = VikBookingTracker::countTrackedRecords($last_month_from, $last_month_to); // percentage of this month and last month (tot_month : x = tot_last_month : 100) $last_mon_divisor = $tot_last_month < 1 ? 1 : $tot_last_month; $pcent_month_full = $tot_month * 100 / $last_mon_divisor; $pcent_month = 0; if ($pcent_month_full > 0 && $pcent_month_full < 100) { // less visitors (-x %) $pcent_month = round((100 - $pcent_month_full), 1); $pcent_month = $pcent_month - ($pcent_month * 2); } elseif ($tot_last_month > 0 && $pcent_month_full > 100) { // more visitors (+x %) $pcent_month = '+' . round(($pcent_month_full - 100), 1); } elseif ($pcent_month_full > 0 && $tot_month != $tot_last_month) { // more visitors (+x %) $pcent_month = '+' . round($pcent_month_full, 1); } echo implode(';', array($tot_today, $tot_month, $tot_last_month, $pcent_month)); } public function render(?VBOMultitaskData $data = null) { // increase widget's instance counter static::$instance_counter++; // check whether the widget is being rendered via AJAX when adding it through the customizer $is_ajax = $this->isAjaxRendering(); // generate a unique ID for the sticky notes wrapper instance $wrapper_instance = !$is_ajax ? static::$instance_counter : rand(); $wrapper_id = 'vbo-widget-visitscounter-' . $wrapper_instance; ?>

widgetIcon; ?> widgetName; ?>

0
0
0
0 %