Loading counter.info.yml +1 −1 Original line number Diff line number Diff line name: Counter type: module description: This module used for displaying a Site Counter, Node Count, Unique Visitor and Client IP. description: This module is used for displaying details like Site Counter, Node Count, Unique Visitor and Client IP in a block. core_version_requirement: ^8.8 || ^9 package: Statistics configure: counter.settings counter.install +8 −108 Original line number Diff line number Diff line Loading @@ -5,97 +5,6 @@ * Install and uninstall functions for the Counter module. */ /** * Implements hook_install(). */ function counter_install() { // Add site counter data counter_data table. $sql = " SELECT count(*) as total FROM {counter} c "; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'site_counter' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name, counter_value) VALUES ('site_counter', '$counter_total')"; \Drupal::database()->query($sql); } // Add unique visitor data to counter_data table. $sql = " SELECT count(*) as total FROM (SELECT ip FROM {counter} GROUP BY ip) c"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unique_visitor' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unique_visitor','$counter_total')"; \Drupal::database()->query($sql); } // Add registered user data to counter_data table. $sql = " SELECT count(*) as total FROM {users_field_data} WHERE access<>0 and uid<>0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'registered_user' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('registered_user', '$counter_total')"; \Drupal::database()->query($sql); } // Add unregistered user data to counter data table. $sql = " SELECT count(*) as total FROM {users_field_data} WHERE access=0 and uid<>0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unregistered_user' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unregistered_user', '$counter_total')"; \Drupal::database()->query($sql); } // Add published node data to counter data table. $sql = " SELECT count(*) as total FROM {node_field_data} WHERE status=1"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'published_node' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('published_node', '$counter_total')"; \Drupal::database()->query($sql); } // Add unpublished node data to counter data table. $sql = " SELECT count(*) as total FROM {node_field_data} WHERE status=0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unpublished_node' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unpublished_node','$counter_total')"; \Drupal::database()->query($sql); } // Add blocked user data to counter data table. $sql = " SELECT count(*) as total FROM {users_field_data} WHERE status=0 and uid<>0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'blocked_user' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('blocked_user','$counter_total')"; \Drupal::database()->query($sql); } } /** * Implements hook_schema(). */ Loading Loading @@ -168,23 +77,6 @@ function counter_schema() { 'primary key' => ['counter_id'], ]; $schema['counter_data'] = [ 'fields' => [ 'counter_name' => [ 'type' => 'varchar', 'length' => 100, 'not null' => TRUE, 'default' => 0, ], 'counter_value' => [ 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 0, ], ], 'primary key' => ['counter_name'], ]; return $schema; } Loading @@ -193,5 +85,13 @@ function counter_schema() { */ function counter_uninstall() { \Drupal::database()->schema()->dropTable('counter'); } /** * Implements hook_update_N(). * * Deletes the unwanted counter_data table. */ function counter_update_8101() { \Drupal::database()->schema()->dropTable('counter_data'); } counter.libraries.yml +2 −6 Original line number Diff line number Diff line counter.custom: version: VERSION version: 1.x css: theme: css/counter.css: {} dependencies: - core/jquery - core/drupal - core/drupal.form counter.links.menu.yml +4 −2 Original line number Diff line number Diff line Loading @@ -13,12 +13,14 @@ counter.basic: counter.advanced: title: 'Advanced Counter' description: 'Configure advanced data for displaying in counter block.' route_name: counter.advanced weight: -16 parent: counter.counter_settings counter.initial: title: 'Initial Counter' description: 'Configure initial values for the counter.' route_name: counter.initial weight: -15 parent: counter.counter_settings counter.module +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ function counter_help($route_name, RouteMatchInterface $route_match) { case 'help.page.counter': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The counter module used for displaying Site Counter') . ' </p>'; $output .= '<p>' . t('The counter module is used for displaying details like Site Counter, Node Count, Unique Visitor and Client IP in a block.') . ' </p>'; return $output; } } Loading Loading
counter.info.yml +1 −1 Original line number Diff line number Diff line name: Counter type: module description: This module used for displaying a Site Counter, Node Count, Unique Visitor and Client IP. description: This module is used for displaying details like Site Counter, Node Count, Unique Visitor and Client IP in a block. core_version_requirement: ^8.8 || ^9 package: Statistics configure: counter.settings
counter.install +8 −108 Original line number Diff line number Diff line Loading @@ -5,97 +5,6 @@ * Install and uninstall functions for the Counter module. */ /** * Implements hook_install(). */ function counter_install() { // Add site counter data counter_data table. $sql = " SELECT count(*) as total FROM {counter} c "; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'site_counter' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name, counter_value) VALUES ('site_counter', '$counter_total')"; \Drupal::database()->query($sql); } // Add unique visitor data to counter_data table. $sql = " SELECT count(*) as total FROM (SELECT ip FROM {counter} GROUP BY ip) c"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unique_visitor' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unique_visitor','$counter_total')"; \Drupal::database()->query($sql); } // Add registered user data to counter_data table. $sql = " SELECT count(*) as total FROM {users_field_data} WHERE access<>0 and uid<>0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'registered_user' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('registered_user', '$counter_total')"; \Drupal::database()->query($sql); } // Add unregistered user data to counter data table. $sql = " SELECT count(*) as total FROM {users_field_data} WHERE access=0 and uid<>0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unregistered_user' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unregistered_user', '$counter_total')"; \Drupal::database()->query($sql); } // Add published node data to counter data table. $sql = " SELECT count(*) as total FROM {node_field_data} WHERE status=1"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'published_node' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('published_node', '$counter_total')"; \Drupal::database()->query($sql); } // Add unpublished node data to counter data table. $sql = " SELECT count(*) as total FROM {node_field_data} WHERE status=0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unpublished_node' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unpublished_node','$counter_total')"; \Drupal::database()->query($sql); } // Add blocked user data to counter data table. $sql = " SELECT count(*) as total FROM {users_field_data} WHERE status=0 and uid<>0"; $counter_total = \Drupal::database()->query($sql)->fetchField(); $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'blocked_user' "; $counter_name_exist = \Drupal::database()->query($sql)->fetchField(); if (!$counter_name_exist) { $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('blocked_user','$counter_total')"; \Drupal::database()->query($sql); } } /** * Implements hook_schema(). */ Loading Loading @@ -168,23 +77,6 @@ function counter_schema() { 'primary key' => ['counter_id'], ]; $schema['counter_data'] = [ 'fields' => [ 'counter_name' => [ 'type' => 'varchar', 'length' => 100, 'not null' => TRUE, 'default' => 0, ], 'counter_value' => [ 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 0, ], ], 'primary key' => ['counter_name'], ]; return $schema; } Loading @@ -193,5 +85,13 @@ function counter_schema() { */ function counter_uninstall() { \Drupal::database()->schema()->dropTable('counter'); } /** * Implements hook_update_N(). * * Deletes the unwanted counter_data table. */ function counter_update_8101() { \Drupal::database()->schema()->dropTable('counter_data'); }
counter.libraries.yml +2 −6 Original line number Diff line number Diff line counter.custom: version: VERSION version: 1.x css: theme: css/counter.css: {} dependencies: - core/jquery - core/drupal - core/drupal.form
counter.links.menu.yml +4 −2 Original line number Diff line number Diff line Loading @@ -13,12 +13,14 @@ counter.basic: counter.advanced: title: 'Advanced Counter' description: 'Configure advanced data for displaying in counter block.' route_name: counter.advanced weight: -16 parent: counter.counter_settings counter.initial: title: 'Initial Counter' description: 'Configure initial values for the counter.' route_name: counter.initial weight: -15 parent: counter.counter_settings
counter.module +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ function counter_help($route_name, RouteMatchInterface $route_match) { case 'help.page.counter': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The counter module used for displaying Site Counter') . ' </p>'; $output .= '<p>' . t('The counter module is used for displaying details like Site Counter, Node Count, Unique Visitor and Client IP in a block.') . ' </p>'; return $output; } } Loading